argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
17.33k stars 5.26k forks source link

Add `author`/`creator` as a template key for Gitlab Pull Request Generator #18826

Closed vfaergestad closed 1 month ago

vfaergestad commented 2 months ago

Summary

The pull request generators support multiple different template keys that are retrieved together with the pull requests from the Gitlab and Github API. The author/creator field is not one of them.

Motivation

When our team uses the Pull request generators, we need to reference which image tag that needs to be used in the generated application. Since we tag our images with $USER-$COMMIT_SHA, (where $USER is the author of the pull request) there is no way for us (that we know of) to reference this image properly in the template.

Proposal

  1. Implement the retrieval of the author/creatorfield in the different pull-request services in /argoproj/argo-cd/v2/applicationset/services/pull_request.
  2. Add the field to /argoproj/argo-cd/applicationset/generator/pull_request.go
  3. Add the key to the documentation at https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Pull-Request/#template

Gitlab exposes this field through the author field in their API: https://docs.gitlab.com/ee/api/merge_requests.html#list-project-merge-requests

Github exposes this field through the creator field in their API: https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests

Gitea exposes this field through the user.loginfield in their API: https://gitea.com/api/swagger#/repository/repoListPullRequests

Bitbucket exposes this field throigh the authorfield in their API: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-get

Azure Devips exposes this field through the createdBy field in their API: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests/get-pull-request?view=azure-devops-rest-7.2#gitpullrequest

vfaergestad commented 2 months ago

I would be willing to provide a PR if approved.

vfaergestad commented 2 months ago

Doing this enhancement, it would be beneficial to research the rest of the git-providers for a similar field as well. Done, found the field in all APIs.

agaudreault commented 2 months ago

@vfaergestad if you start working on this, open a draft PR when you are ready, then you can convert your draft PR to open when you are ready for review :)

vfaergestad commented 2 months ago

I have converted my PR to open. The integration-tests are failing, and I would really like some feedback on why.

The code itself seems to function correctly. I have tested it manually as well with both Gitlab and Github.

ggjulio commented 1 month ago

@vfaergestad just wrote a comment in your PR, see PR #17907 for files to update to fix e2e tests.

@agaudreault sorry for the off-topic. I'm having a hard time to get PR #17907 reviewed. Could you review it ?

vfaergestad commented 1 month ago

@ggjulio Thank you, that did the trick!

@agaudreault Thank you for your pointers as well. I think the PR is ready for a review when someone is available.

vfaergestad commented 1 month ago

Fixed by #18974