GitHub integration sends status from multiple pipelines when using `only/except: external_pull_request`
### Summary With the pipelines for external pull requests, introduced in https://gitlab.com/gitlab-org/gitlab-ce/issues/65139 we are enabling users to run a pipeline in the context of a GitHub pull request. Given the following `.gitlab-ci.yml`: ```yaml always-run: script: echo 'this should always run' on-pull-requests: script: echo 'this should run on pull requests' only: - external_pull_requests except-pull-requests: script: - echo 'this should not run on pull requests' - sleep 20 # make the job fail with a command that does not exist - s except: - external_pull_requests ``` When changes are pushed to the branch we detect that aside from a branch push there is a pull request open on GitHub and we ALSO create a pipeline for the external pull request (as expected by design): ![image](/uploads/f984a88f76afa90820cd145df3fec4b5/image.png) In the screenshot above, pipeline `12648771` (which is successful) is for the external pull request while pipeline `12648770` (which is failed) is for the branch push. On GitHub, we update the status of the pull request with the status of the pipeline that finishes last ![image](/uploads/ba2e180c7e0fa6430d365404e214f3d2/image.png) In the case above, we updated the status as failed. ### Steps to reproduce * create new project as CI/CD for external repo * select GitHub as option * import repository * GitHub integration should also be active * add a `.gitlab-ci.yml` on GitHub repository containg the yaml above * push changes to GitHub, to a new branch, and open a pull request * pushing new changes to the same branch, this time, we should see 2 pipelines being created * the failing pipeline is for the branch push and the passing pipeline is for the pull request * Github status shows failing pipeline ### What is the current *bug* behavior? We send to GitHub the status of the latest pipeline which in this case could be in the context of the `branch` ### What is the expected *correct* behavior? We should send to GitHub the status of the pull request pipeline ### Possible fixes When the `.gitlab-ci.yml` does not contain any `only/except: external_pull_requests` perhaps the user wants to still see the status of the branch pipeline in the pull request. However, in presence of `only/except: external_pull_requests` we should choose to send the status of the pipeline for external pull request over the pipeline for the branch. ## Workaround It should be possible to avoid that by ensuring that by ensuring no jobs run on `branches`: ```yaml always-run: script: echo 'this should always run' except: - branches on-pull-requests: script: echo 'this should run on pull requests' only: - external_pull_requests except-pull-requests: script: - echo 'this should not run on pull requests' - sleep 20 # make the job fail with a command that does not exist - s except: - branches - external_pull_requests ```
issue