Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

feat: Add pull request support to SCM generator #469

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fardin01
Copy link

@fardin01 fardin01 commented Jan 20, 2022

This commit adds pull request support to SCM generator so the generator
can create ArgoCD apps for PRs as well.

Fixes #466

Signed-off-by: Fardin Khanjani [email protected]

@fardin01
Copy link
Author

fardin01 commented Feb 4, 2022

Waiting for #472 to be merged.

@fardin01 fardin01 changed the title Add pull request support to SCM generator feat: Add pull request support to SCM generator Feb 23, 2022
api/v1alpha1/applicationset_types.go Outdated Show resolved Hide resolved
Comment on lines 315 to +318
// Scan all branches instead of just the default branch.
AllBranches bool `json:"allBranches,omitempty"`
// Scan all pull requests
AllPullRequests bool `json:"allPullRequests,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be documentation on what to expect the generator to return if both allBranches and allPullRequests are true.

pkg/services/scm_provider/github.go Show resolved Hide resolved
allPullRequests: true,
url: "[email protected]:argoproj/applicationset.git",
branches: []string{"pr-1", "pr-2"},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need a test case for both allPullRequests and allBranches being true, whatever the behavior might be in that case.

name: "all pull requests",
allPullRequests: true,
url: "[email protected]:argoproj/applicationset.git",
branches: []string{"pr-1", "pr-2"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this test means... if we're listing pull requests, what is the meaning of checking the results for two branches named pr-1 and pr-2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I misunderstood what this test actually does. So it gets real data from applicationset Github repo and tests against that. In that case, in order to test for pull requests, we'll have to open a "dummy" PR and keep it always open for this purpose. Does that sound alright?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, we can do that with allPullRequests set to true and a filter to look for a specific PR. We can't realistically list all the PRs and check if their branch is what we expect them to be. We could set allPullRequests to true and check for the response code. How does that sound?

return false, nil
}

if filter.PullRequestLabelMatch != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this performs the same check as filter.LabelMatch, why not just use that filter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With adding the PullRequest field to the Repository struct, we can keep this and range through repo.PullRequest.Labels instead of repo.Labels.
#469 (comment)

Copy link
Member

@crenshaw-dev crenshaw-dev Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think that's the way to go.

Will need to consider how to treat a pull-request filter placed on an SCM generator where pull request fetching isn't enabled. Ignore, log error, etc.

pkg/services/scm_provider/gitlab.go Outdated Show resolved Hide resolved
@@ -342,6 +346,10 @@ type SCMProviderGeneratorFilter struct {
LabelMatch *string `json:"labelMatch,omitempty"`
// A regex which must match the branch name.
BranchMatch *string `json:"branchMatch,omitempty"`
// A regex which must match the pull request tile.
PullRequestBranchMatch *string `json:"pullRequestTitleMatch,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be two filters, one to match source branches, and the other to match target branches?

Copy link
Author

@fardin01 fardin01 Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting point! I can't recall ever seeing a source branch being merged into a non-default target branch (main, master etc.). In addition, usually, all source branches get merged into one single target branch (otherwise you got a very messy repo 😄 ) which makes filtering the target branch pointless. So IMHO this feature would only support a "corner case". What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider this use case: I want to spin up test environments for each PR against main. Developer A opens a PR from feature/whatever to main. Developer B has suggestions but instead of writing them all out, just opens a PR from feature/whatever-review to feature/whatever.

I think this is common enough to justify giving the AppSet the designer to avoid creating an App for that second PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if it ends up being a lot of work, we could certainly leave it for a future enhancement.

pkg/services/scm_provider/gitlab.go Outdated Show resolved Hide resolved
pkg/services/scm_provider/utils.go Show resolved Hide resolved
…enerator

can create ArgoCD apps for PRs as well.

Fixes argoproj#466

Signed-off-by: Fardin Khanjani <[email protected]>
@fardin01
Copy link
Author

fardin01 commented Apr 5, 2022

@rishabh625 Please feel free to move this PR over to argocd repo. I should have some time to get back at this pretty soon. Thanks :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SCM Provider with Pull Requests
2 participants