github-pr-resource icon indicating copy to clipboard operation
github-pr-resource copied to clipboard

Add branch (headRefName) source filter

Open chrisfarms opened this issue 3 years ago • 4 comments

What

Allows setting a "branch" in the source configuration, that filters the PR versions down to only those with a matching headRefName.

Why

When using instanced pipelines (one-pipeline-per-pr) it is desirable to monitor changes only for an individual PR and not all PRs. Pinning the resource version is not suitable for this use-case as the version contains the "commit" (we still want the resource to trigger on commit changes, we just only want to track those for a single PR).

Ideally we could filter by PR-number or some other unique ID, however the GraphQL API does not expose this, and we want to avoid filtering client-side.

Note

There should be a one-to-one mapping of headRefName to PR in most real-world usage, and so for this "one-pipeline-per-pr" use case, it is probably "good enough". However there is nothing stopping branch names getting reused over time, so you should not consider setting "branch" the same as "pinning" a resource version, it is merely a filter like state.

chrisfarms avatar Mar 30 '21 16:03 chrisfarms

@chrisfarms Does Concourse's partial version pinning help in this case (concourse/concourse#4380)? I think that would allow you to pin version.pr. I may be misunderstanding how the partial version pinning works though.

vixus0 avatar May 12 '21 07:05 vixus0

Does Concourse's partial version pinning help in this case

Interesting @vixus0 .... I think could ... but the pr-resource does not seem to emit ALL versions during check, and so you get a state where the only version in the list returned from check would be for some other random PR won't match the version at all, and it becomes a game of probability wether it works or not.

By explicitly scoping the resource to a single PR (well branch) you get to treat the PR-resource more like you treat the git-resource, following commits on a single branch and not caring about other unrelated PRs as they change state.

chrisfarms avatar May 28 '21 10:05 chrisfarms

Yeah also I realise now the partial pinning results in weirdness with get steps passed param. In any case I'd like to see this PR merged 💯

vixus0 avatar Jun 01 '21 13:06 vixus0

We tried the partial pinning approach and found new commits on the PRs don't trigger new builds, so I'd be interested in having this merged and released.

Mike-Dax avatar Jul 06 '21 06:07 Mike-Dax