Gitlab: How to approve merge request from myself - gitlab

The gitlab project is hosted at my company and created from some common template. I am the maintainer of the project.
I made code change, committed the branch and, at gitlab page, I created the merge request. The problem is, the "Merge" button is greyed out and I do not receive approval request email, so I am stuck here and have to wait for my colleague to approve it before I can merge. Is there a way I can make the merge before that?
I already tried the following at the project setting.
At "Merge request approvals", there is a rule mandates the minimum number of approvals. I deleted my colleagues from approvers list, just left myself; I also changed the minimum number to 0.
"Prevent approval of merge requests by merge request author" is unchecked
"Prevent approval of merge requests by merge request committers" is unchecked
In "repository" --> "Protected branch", I added 2 rules, one for the default branch of the project and one for the branch I just committed. The content of both rules are same, "allowed to merge" and "allowed to push" are "Maintainer + developer" and, the key is, "code owner approval" is slide off.
But after all these, that "Merge" button at my merge request page is still disabled; the strange thing is, just above that button, I can see "Requires approval from Owners" is check marked.
Any suggestion?

Related

Enabling pre-receive server hook to get PR/MR approval before pushing to dev branch

Use case: I have code on my local machine and If I try to push it to remote server, a pre-receive hook in remote [GitLab] server should get triggered and ask for respective author approval to merge that code onto Gitlab repo.
After [code review] if author approves MR then code from my local repo will be pushed to remote server else push needs to be halted.
I am sure that I was asked to enable pre-receive hook on GitLab server side and not on client side.
I think it is not possible because code exists in developer's local machine and hence approver may not be able to do code review but not sure about pre-receive working.
Can pre-receive hook able to notify approver before code push? If it is possible need to know how?
If not, I want a strong valid point to negotiate😒
MR approval is not requested when one pushed a branch, but only when one makes (once the branch is pushed) a merge request to the target branch.
In your case:
protect the dev branch (nobody can push directly to it, so no need for a pre-receive hook)
make a merge request mandatory for that branch
make sure to configure your merge requests so that they must be approved before they can be merged.
That means any code eventually merged to dev:
will not have been pushed directly to dev (MR required)
will have been reviewed and approved first, before being accepted and merged to dev.
While it is true enforcing the MR approval process, meaning disabling the "Merge" button as long as approval is not met, is not free (premium only), you still have a way to enforce it.
Make sure nobody can push/merge to dev is a "Merge Manager" who is alone responsible to merge or not the MRs. If said merge manager sees there is no approval, they won't merge the MR.

Set default reviewers for merge request in GitLab

How I can set default reviewers in GitLab Premium?
In Settings → General I have only Merge request (MR) approvals, not reviewers.
There is no such setting in the UI. If you think it would be useful to others, please file a feature request.
As a workaround, you could use the Merge requests API to set reviewers when creating the MR or by updating it after creation.
How you want to achieve the desired result depends on your workflow.
For example, you could have something subscribe to the project webhook which triggers a script that does the API call whenever it sees an open MR event.
Another option, if you run pipelines on MRs, you can have a job run a script which could set reviewers if none are already set via the API.
Yet another option would be to have a specified reviewer set when a merge request is created through the /assign_reviewer #user quick action by adding it to the default and all MR template files.
You can use "Default description template for merge requests" either via Settings->Merge Requests or via file in .gitlab/merge_request_templates to do it via a workaround. (Doc)
In the template you can use the chat code
/assign_reviewer #user1 #user2 #user3
to automatically assign user1, user2 and user3 as reviewers when creating a new MR.
Might be a useful workaround as this does not add you as a reviewer. (especially for gitlab free/CE 14.8+, as multiple reviewers are only available for Premium)
You could add a Reviewers section to your default MR template. Then persons will be notified with a Todo for the MR upon creation.
This should be in your default branch.
.gitlab/merge_request_templates/default.md
## What this MR does / why we need it
- description
- proof of work
## Reviewers
- [ ] Reviewed by #gitlabUser1
- [ ] Reviewed by #gitlabUser2
- [ ] Reviewed by #gitlabUser3
- [ ] Reviewed by #gitlabUser4
- [ ] Reviewed by #gitlabUser5
Thanks for your MR, you're awesome! :+1:
The user can then check the checkbox upon review which will change the MR history too.
Could you please try below
In Settings-->General-Merge Request Approvals.
Click on Add approval Rule.
Add Rule name as "Default", Approvals required, desired branch and add members under approvers.
These approvers would be your default reviewers for any Merge request.

Description of "Allow requestors to approve their own changes" is confusing

The description on this page https://learn.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops#require-a-minimum-number-of-reviewers says:
If Allow requestors to approve their own changes is selected, the creator of the pull request may vote on its approval. If not, they can still vote Approve on their pull request, but their vote won't count toward the Minimum number of reviewers.
This means it is assumed that the person that did changes on the source branch is at the same time the creator of the pull request. In our case often a different person than the developer is creating the pull request. Is this setting then only related to the creator of the pull request (and not caring about the commit pusher) or the person that pushed commits to be reviewed within the pull request?
If it is only about the creator of the pull request then the name of this setting should be changed since it has nothing to do with the actual changes (=commits) on source branch of the pull request.
Did I misunderstand something here?
Thank you
You are making a good point, Azure DevOps is implying here that the person who worked on a branch is also the initiator of the PR. This is not something that is 100% guaranteed, because it can happen that I created a dev branch, worked on code, made several commits, then my teammate creates a PR from my branch.
(The "most recent pusher" setting is probably closer to what you are looking for, which controls based on who pushed the latest commit from a local repository.)

Can I tell who approved merge requests?

I have GitLab Starter which seems to mean that I am unable to restrict code approvers on a directory basis as everyone needs developer level access.
This is causing slight headaches.
Is there a way in GitLab that I can review who approved groups of merge requests? This way I can at least check after the fact that no one has approved code who should not have.
Is there a way to query the backend database or a way of gaining this information in some GUI screen somewhere?
There will be a way, with the upcoming GitLab 13.5 to clearly see the status of the approval process and who has approved a MR.
In the meantime, you still have the GitLab Merge Request approval API and the merge request API, with a call like GET /merge_requests does include paramters like approver_ids
Returns merge requests which have specified all the users with the given ids as individual approvers.
None returns merge requests without approvers.
Any returns merge requests with an approver.
That could help checking who has approved a MR.
Users on GitLab Starter, Bronze, or higher will also see the approvals_before_merge parameter.

Workflow logic for multiple-approval process

I have the need to create a workflow that will begin when a user submits an infopath form to a document library. Some fields will be extracted from this form to build the workflow.
Steps:
Notify the form submitter's manager and request that they approve or disapprove.
One or more other users will be notified and requested to approve or disapprove the submitted form. If any of them reject the form, the original requester should be notified and requested to re-submit the form.
I can make a workflow for step 1 and then check the value of that field in the task to see if it's either approved or disapproved before moving onto the next step or not.
The issue I'm having is how to check whether someone has rejected or approved in the 2nd step, since there could be multiple users.
Any help is greatly appreciated
After step 1, you can track the workflow in the "workflow Tasks" list, i.e., you can get who rejected it, when they did it and why they did it(if you have a notes/reason column).
If you/your company can afford to buy a third party tool like nintex/bamboo workflow conductor/k2, this approval process come out of the box. They are a bit expensive though

Resources