Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request generator not working for Bitbucket Cloud #20769

Closed
3 tasks done
mpitt opened this issue Nov 12, 2024 · 9 comments · Fixed by #20990
Closed
3 tasks done

Pull Request generator not working for Bitbucket Cloud #20769

mpitt opened this issue Nov 12, 2024 · 9 comments · Fixed by #20990
Assignees
Labels
bug Something isn't working version:2.13 Latest confirmed affected version is 2.13

Comments

@mpitt
Copy link

mpitt commented Nov 12, 2024

Checklist:

  • I've searched in the docs and FAQ for my answer: https://bit.ly/argocd-faq.
  • I've included steps to reproduce the bug.
  • I've pasted the output of argocd version.

Describe the bug

Using the Pull Request generator with Bitbucket Cloud results in the error

error listing repos: error unmarshalling json to type '[]BitbucketCloudPullRequest': json: cannot unmarshal object into Go struct field BitbucketCloudPullRequest.author of type string

It looks like the error can be traced to adding the author field with the wrong type in [1]: it was added as a string but in the Bitbucket Cloud API it's an object [2]

To Reproduce

Create an ApplicationSet with the Pull Request generator:

spec:
  generators:
    - pullRequest:
        bitbucket:
          basicAuth:
            passwordRef:
              key: password
              secretName: argocd-controller-secret
            username: Srv-CICD-Robot
          owner: REDACTED
          repo: REDACTED
        filters:
          - branchMatch: .*/.*REDACTED.*/.*
        requeueAfterSeconds: 60

Expected behavior

The PR generator can parse the Bitbucket API response, where the author field is an object and not a string.

Screenshots

N/A

Version

argocd: v2.13.0+347f221
  BuildDate: 2024-11-04T12:09:06Z
  GitCommit: 347f221adba5599ef4d5f12ee572b2c17d01db4d
  GitTreeState: clean
  GoVersion: go1.23.1
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.13.0+347f221

Logs

error listing repos: error unmarshalling json to type '[]BitbucketCloudPullRequest': json: cannot unmarshal object into Go struct field BitbucketCloudPullRequest.author of type string
@mpitt mpitt added the bug Something isn't working label Nov 12, 2024
@andrii-korotkov-verkada andrii-korotkov-verkada added the version:2.13 Latest confirmed affected version is 2.13 label Nov 13, 2024
@andrii-korotkov-verkada
Copy link
Contributor

I see the object is

      "author": {
        "type": "<string>"
      },

@andrii-korotkov-verkada
Copy link
Contributor

Do you know what the type means here? In ArgoCD the data is passed to the Author field of the PullRequest, which expects an author of the PR. Should I just pass the type value?

@andrii-korotkov-verkada andrii-korotkov-verkada added the more-information-needed Further information is requested label Nov 17, 2024
@andrii-korotkov-verkada
Copy link
Contributor

Also, did Bitbucket Cloud always have author as an object?

@mpitt
Copy link
Author

mpitt commented Nov 18, 2024

Do you know what the type means here? In ArgoCD the data is passed to the Author field of the PullRequest, which expects an author of the PR. Should I just pass the type value?

The API documentation is indeed a bit confusing. You have to click "Show child properties" multiple times to see all the fields but in the end you get this:
image

The type field seems to be supporting some form of "typed JSON" convention, it's always "user".

There are 3 possible fields I see in the API:

  • author.display_name (can contain spaces etc., seems to be the "Full name" of the Atlassian profile)
  • author.uuid (meaningless, but unique and has a well defined format)
  • author.nickname (undocumented, seems to correspond to the "Public name" of the Atlassian profile)

Weirdly, there is no field for the Bitbucket username.

@andrii-korotkov-verkada andrii-korotkov-verkada removed the more-information-needed Further information is requested label Nov 18, 2024
@andrii-korotkov-verkada
Copy link
Contributor

Which field should we use in your opinion? display_name, nickname, or some combination of all 3 fields?

@mpitt
Copy link
Author

mpitt commented Nov 18, 2024

Without knowing a lot on how the Author field of PullRequest is intended to be used (is it documented? I can't find it here), and guessing at what other SCMs might return:

I would go with a lightly sanitised version of nickname (spaces and some special characters replaced with -), with a fallback on display_name, sanitised the same way, if nickname is not present (being an undocumented field). Or if the fallback logic is too much of a hassle, just the sanitised display_name would be fine too, I suppose.

That's on the assumption that the Author field might be used to template some values, that e.g. might expose an app under a certain subdomain, so the sanitisation should produce a suitable value. But that might not be a strict requirement, and maybe something to implement at a higher level for all the SCMs?

@andrii-korotkov-verkada
Copy link
Contributor

I've taken a look. Seems like it's used for revision metadata, e.g. for displaying in the UI. Various other places seem to use username for this field.

@andrii-korotkov-verkada
Copy link
Contributor

Is nickname the closest to username? Why does it need to be sanitized?

@andrii-korotkov-verkada andrii-korotkov-verkada added the more-information-needed Further information is requested label Nov 22, 2024
@mpitt
Copy link
Author

mpitt commented Nov 28, 2024

Yes, I think nickname is the closest. If it's only used in the UI and as a bit of metadata, no need to sanitise it.

@andrii-korotkov-verkada andrii-korotkov-verkada removed the more-information-needed Further information is requested label Nov 28, 2024
andrii-korotkov-verkada added a commit to andrii-korotkov-verkada/argo-cd that referenced this issue Nov 28, 2024
Fixes argoproj#20769

Author there is a struct, not a string. Use nickname from that struct as an author name.

Let's cherry pick to 2.11-2.13

Signed-off-by: Andrii Korotkov <[email protected]>
ishitasequeira pushed a commit that referenced this issue Dec 3, 2024
Fixes #20769

Author there is a struct, not a string. Use nickname from that struct as an author name.

Let's cherry pick to 2.11-2.13

Signed-off-by: Andrii Korotkov <[email protected]>
gcp-cherry-pick-bot bot pushed a commit that referenced this issue Dec 3, 2024
Fixes #20769

Author there is a struct, not a string. Use nickname from that struct as an author name.

Let's cherry pick to 2.11-2.13

Signed-off-by: Andrii Korotkov <[email protected]>
ishitasequeira pushed a commit that referenced this issue Dec 3, 2024
… (#21039)

Fixes #20769

Author there is a struct, not a string. Use nickname from that struct as an author name.

Let's cherry pick to 2.11-2.13

Signed-off-by: Andrii Korotkov <[email protected]>
Co-authored-by: Andrii Korotkov <[email protected]>
adriananeci pushed a commit to adriananeci/argo-cd that referenced this issue Dec 4, 2024
argoproj#20990)

Fixes argoproj#20769

Author there is a struct, not a string. Use nickname from that struct as an author name.

Let's cherry pick to 2.11-2.13

Signed-off-by: Andrii Korotkov <[email protected]>
Signed-off-by: Adrian Aneci <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working version:2.13 Latest confirmed affected version is 2.13
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants