Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gitlab: skip source branch with equal name from forked projects
The "source_branch" information from MR objects doesn't contain the project from which this branch comes from and the only place in the code where the source branch is specified on search operation is when the user doesn't explicitly specifies what's the MR ID on CLI and let lab "guess" the right MR ID based on the current checked-out branch which, obviously, is related to a single project ID. In the above case, the branch name is used as "source_branch" in the search operation, however, if any MR has its source branch with same name, but coming from another, forked, project, it'll be in the mix of found MRs, possibly returning the wrong ID. For instance, if the user has the "test" branch checked out which is present in the "test-project" project, but the following MRs exist: MR 1 source branch: "https://gitlab.com/test-project/test" MR 2 source branch: "https://gitlab.com/fork-from-test-project/test" In the current state, both MR 1 and 2 are returned. However, the correct would be to return only MR 1. This patch fixes this wrong behavior by checking the mr.SourceProjectID and mr.ProjectID based on the following statement from API doc [1]: "project_id represents the ID of the project where the MR resides. project_id always equals target_project_id. In the case of a merge request from the same project, source_project_id, target_project_id and project_id are the same. In the case of a merge request from a fork, target_project_id and project_id are the same and source_project_id is the fork project’s ID. " [1] https://docs.gitlab.com/ee/api/merge_requests.html#list-project-merge-requests Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
- Loading branch information