Support `only/except: merge_requests` for external repos
Problem to solve
GitLab CI has an "external repos" capability intended to allow customers to use GitHub for source control and GitLab CI, however the CI_PIPELINE_SOURCE always shows
push because it is based on the pull mirror rather than the source GitHub repo or webhook. This prevents GitLab CI with External Repos from supporting the
only/except: merge_requests options.
Large projects with a need to separate short running tests from longer running tests. As a customer with a complex CI pipeline, it is common to give developers quick feedback on atomic commits, while having more robust testing patterns run prior to merging to master. This separation of tests needs to be enforced, and can't rely on manual triggering of jobs. The ability to use
only/except: merge_requests cases in pipelines is vital to achieving feature parity with competing CI products.
One customer with these requirements is open to considering workarounds, as long as they meet their ultimate requirement of being able to have separate sets of test run based on the event that triggered the pipeline (commit vs Pull Request). As noted here https://blog.dachary.org/2014/12/01/copy-a-github-pull-request-to-gitlab/ it may be possible to infer a Pull Request from the refs/pull/N/head reference to the base of the pull request in the git repo after the mirror has been refreshed.
Or if we could have GitHub fire different webhooks and GitLab could persist that info long enough to put in a CI variable, then we could achieve similar branching.
As implemented in gitlab!15082 (merged):
This issue introduces support for
only/except: external_pull_requests when using the project for CI/CD only with a GitHub repository. When using
only/except: external_pull_requests we allow jobs to be created for a pipeline if a GitHub pull request is open for the given
When using a mirror for CI/CD only we register a pull_request webhook. When a pull_request webhook is received for the pull request being created, if the repository already contains the SHA related to the pull request, we create immediately a new pipeline. Otherwise we store the pull request info for when changes are pushed to branches. When changes are pushed to branches we check if any pull requests are opened for the given ref and create pipelines for pull requests.
Next follow up is adding support for forks: gitlab#5667