Label and notify of upcoming close for stale MRs (Step 2 part 1)
What does this MR do?
Run a script to:
- Label all stale MRs with the stale - to be closed label
- Make a comment on the MR saying the MR will be closed and the associated branch deleted within 7 days unless the stale - to be closed label is removed.
Tasks
-
Write script -
Ensure it preserves existing labels -
Ensure it can be re-run idempotently without double-creating notes. -
Ensure we don't exceed the rate limit: https://docs.gitlab.com/ee/user/gitlab_com/index.html#haproxy-api-throttle - Use CURL to check current ratelimit quotas:
curl -i "https://gitlab.com/api/v4/version?private_token=$PRIVATE_TOKEN" | grep ratelimit
- Use CURL to check current ratelimit quotas:
-
Run the script against the www-gitlab-com
repo -
Capture the script output to a text file, and save it on this issue under Script Run Logs
below. -
Send the slack notification to the #handbook
,#website
, and#whats-happening-at-gitlab
channels.
MR Note Text
This Merge Request has not been updated in over 30 days, and has been labeled ~"stale - to be closed" ([see entire list](#{mr_labels_url})). In 7 more days, it will be closed, and its branch will be deleted.
**To keep this Merge Request open and prevent its branch from being deleted, remove the ~"stale - to be closed" label within 7 days**.
The branches have been archived in the [`www-gitlab-com-archive-20200410-pre-cleanup`](https://gitlab.com/gitlab-com/www-gitlab-com-archive-20200410-pre-cleanup) project prior to deletion.
**If you want to access the branch after it has been deleted, do the following**:
1. Go to the [`www-gitlab-com-archive-20200410-pre-cleanup`](https://gitlab.com/gitlab-com/www-gitlab-com-archive-20200410-pre-cleanup) project
1. [Clone the repository](https://docs.gitlab.com/ee/gitlab-basics/start-using-git.html#clone-a-repository) and check out the branch locally. You have two options here:
* Clone it to a new repo, if you just want to access commits on the branch locally, or
* Add it as a remote to an existing clone of the `www-gitlab-com` repo, if you want to re-push the branch to recreate it there.
Slack Notification Text
Hi team,
On 2020-04-20 we are planning on doing a cleanup of the https://gitlab.com/gitlab-com/www-gitlab-com repo to close stale MRs (no activity in last 30 days). The MRs' branches and other stale branches will be deleted soon after.
This is a second heads-up for team members about this upcoming action.
All MRs which are scheduled to be closed have already had the `~"stale - to be closed"` label applied, and a comment/note added notifying about the upcoming closure. You should have received a notification/email if you were following the MR.
You can also view all your own stale open MRs by adding your GitLab username to the end of this URL and entering it into your browser: https://gitlab.com/gitlab-com/www-gitlab-com/-/merge_requests?state=opened&label_name%5B%5D=stale%20-%20to%20be%20closed&author_username=
If you want to keep a Merge Request open and prevent its branch from being deleted, remove the `~"stale - to be closed"` label within 7 days
Stale branches can be viewed here: https://gitlab.com/gitlab-com/www-gitlab-com/-/branches/stale
If you have any questions or concerns please reach out on this issue: https://gitlab.com/gitlab-com/www-gitlab-com/-/issues/5525
Dev Notes
-
Unfortunately,we will have to use the Rest API ~~and retrieve every MR in the project (currently ~46,000) to accomplish this, which will be slow because it has to retrieve the full content of every MR.~~ This is because the alternatives to avoid this are not available (**UPDATE: This will not actually be slow, because we can pass thestate
filter to the RESTmerge_requests
endpoint**):- There's a bug in the GraphQL API, and the
mergeRequests
resource to return multiple merge requests does not work. Issue here: gitlab-org/gitlab#34527 (closed) - The Project Merge Requests search doesn't allow filtering by
state
: https://gitlab.com/groups/gitlab-com/-/merge_requests (this would still retrieve all the data for each MR, but fewer of them) - Not sure if the Advanced Global Search would help, but it's not available on gitlab.com anyway: https://docs.gitlab.com/ee/user/search/advanced_global_search.html
- There's a bug in the GraphQL API, and the
- Example CURL command:
curl "https://gitlab.com/api/v4/projects/18061960/merge_requests?private_token=$PRIVATE_TOKEN&state=opened&view=simple&per_page=1" | jq
Related issues
Relates #5525 (closed)
Edited by Ryan Wells