Skip to content

Remove draft status when moving security MR to canonical

Steve Abrams requested to merge delivery19798-remove-draft into master

What does this MR do and why?

When a security blog post MR is moved to canonical, we need to ensure the Draft status is removed so that it is mergeable on canonical.

Related to gitlab-com/gl-infra/delivery#19798 (closed)

Testing

I used https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/164 to test this change.

I commented out all of the code we don't need to test in MoveBlogPost so the move doesn't occur and we only check the draft remova:

git diff
diff --git a/lib/release_tools/security/publish/move_blog_post.rb b/lib/release_tools/security/publish/move_blog_post.rb
index e2bdbe2a..b2cac0ab 100644
--- a/lib/release_tools/security/publish/move_blog_post.rb
+++ b/lib/release_tools/security/publish/move_blog_post.rb
@@ -22,24 +22,24 @@ module ReleaseTools
           if security_blog_merge_request.present?
             remove_draft_status

-            ReleaseTools::Security::CopyMergeRequestToCanonical.new(
-              security_blog_merge_request,
-              handbook_repository,
-              ReleaseTools::Security::BlogMergeRequest
-            ).execute
-
-            if canonical_blog_merge_request
-              close_security_blog_merge_request
-            else
-              logger.warn(
-                'No canonical blog merge request found, skipping closing the security blog merge request',
-                url: security_blog_merge_request.web_url
-              )
-
-              raise CanonicalMergeRequestNotFoundError
-            end
-
-            send_slack_notification(:success)
+            # ReleaseTools::Security::CopyMergeRequestToCanonical.new(
+            #   security_blog_merge_request,
+            #   handbook_repository,
+            #   ReleaseTools::Security::BlogMergeRequest
+            # ).execute
+
+            # if canonical_blog_merge_request
+            #   close_security_blog_merge_request
+            # else
+            #   logger.warn(
+            #     'No canonical blog merge request found, skipping closing the security blog merge request',
+            #     url: security_blog_merge_request.web_url
+            #   )
+
+            #   raise CanonicalMergeRequestNotFoundError
+            # end
+
+            # send_slack_notification(:success)
           else
             logger.fatal('Security blog merge request not found')

We start with the MR in draft status: TEST blog post - DO NOT USE. I ran the service twice to show that it does not make a request to remove the draft status if the MR is not in draft.

[1] pry(main)> ReleaseTools::Security::Publish::MoveBlogPost.new.execute
2023-11-03 08:58:09.037366 D ReleaseTools::GitlabClient -- [HTTParty] [2023-11-03 08:58:09 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fwww-gitlab-com/merge_requests" -
2023-11-03 08:58:09.037993 I ReleaseTools::Security::Publish::MoveBlogPost -- Moving security blog post to canonical -- {:merge_request=>164, :url=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/164"}
2023-11-03 08:58:10.036776 D ReleaseTools::GitlabClient -- [HTTParty] [2023-11-03 08:58:10 -0600] 200 "PUT https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fwww-gitlab-com/merge_requests/164" -
=> #<Gitlab::ObjectifiedHash:217240 {hash: {"id"=>259857517, "iid"=>164, "project_id"=>21005471, "title"=>"TEST blog post - DO NOT USE", "description"=>"Add blog post for 16.5.1, 16.4.2, 16.3.6 patch release.\n\n\n- [ ] Complete any sections of the blog post that have TODO in their content.\n\nSecurity release tracking issue: https://gitlab.com/gitlab-org/gitlab/-/issues/426612", "state"=>"opened", "created_at"=>"2023-10-27T17:29:00.150Z", "updated_at"=>"2023-11-03T14:58:09.479Z", "merged_by"=>nil, "merge_user"=>nil, "merged_at"=>nil, "closed_by"=>nil, "closed_at"=>nil, "target_branch"=>"master", "source_branch"=>"create-16-5-1--16-4-2--16-3-6-post", "user_notes_count"=>0, "upvotes"=>0, "downvotes"=>0, "author"=>{"id"=>2324599, "username"=>"gitlab-release-tools-bot", "name"=>"GitLab Release Tools Bot", "state"=>"active", "locked"=>false, "avatar_url"=>"https://gitlab.com/uploads/-/system/user/avatar/2324599/avatar.png", "web_url"=>"https://gitlab.com/gitlab-release-tools-bot"}, "assignees"=>[], "assignee"=>nil, "reviewers"=>[], "source_project_id"=>21005471, "target_project_id"=>21005471, "labels"=>["automation:bot-authored", "patch release post"], "draft"=>false, "work_in_progress"=>false, "milestone"=>{"id"=>3094094, "iid"=>93, "group_id"=>9970, "title"=>"16.6", "description"=>"", "state"=>"active", "created_at"=>"2023-05-09T04:50:08.194Z", "updated_at"=>"2023-08-22T21:35:28.795Z", "due_date"=>"2023-11-10", "start_date"=>"2023-10-18", "expired"=>false, "web_url"=>"https://gitlab.com/groups/gitlab-org/-/milestones/93"}, "merge_when_pipeline_succeeds"=>false, "merge_status"=>"can_be_merged", "detailed_merge_status"=>"mergeable", "sha"=>"215e9e66422d1fb3db1d558b8f432242b71f8669", "merge_commit_sha"=>nil, "squash_commit_sha"=>nil, "discussion_locked"=>nil, "should_remove_source_branch"=>nil, "force_remove_source_branch"=>true, "prepared_at"=>"2023-10-27T17:29:18.645Z", "reference"=>"!164", "references"=>{"short"=>"!164", "relative"=>"!164", "full"=>"gitlab-org/security/www-gitlab-com!164"}, "web_url"=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/164", "time_stats"=>{"time_estimate"=>0, "total_time_spent"=>0, "human_time_estimate"=>nil, "human_total_time_spent"=>nil}, "squash"=>false, "squash_on_merge"=>false, "task_completion_status"=>{"count"=>1, "completed_count"=>0}, "has_conflicts"=>false, "blocking_discussions_resolved"=>true, "approvals_before_merge"=>nil, "subscribed"=>true, "changes_count"=>"1", "latest_build_started_at"=>"2023-10-27T17:29:13.728Z", "latest_build_finished_at"=>"2023-10-27T17:39:05.280Z", "first_deployed_to_production_at"=>nil, "pipeline"=>{"id"=>1052441157, "iid"=>983, "project_id"=>21005471, "sha"=>"fdd094187faa1512e3edcd4584ea945ff3be43d5", "ref"=>"refs/merge-requests/164/head", "status"=>"success", "source"=>"merge_request_event", "created_at"=>"2023-10-27T17:29:11.207Z", "updated_at"=>"2023-10-27T17:39:05.306Z", "web_url"=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/pipelines/1052441157"}, "head_pipeline"=>{"id"=>1052441157, "iid"=>983, "project_id"=>21005471, "sha"=>"fdd094187faa1512e3edcd4584ea945ff3be43d5", "ref"=>"refs/merge-requests/164/head", "status"=>"success", "source"=>"merge_request_event", "created_at"=>"2023-10-27T17:29:11.207Z", "updated_at"=>"2023-10-27T17:39:05.306Z", "web_url"=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/pipelines/1052441157", "before_sha"=>"0000000000000000000000000000000000000000", "tag"=>false, "yaml_errors"=>nil, "user"=>{"id"=>2324599, "username"=>"gitlab-release-tools-bot", "name"=>"GitLab Release Tools Bot", "state"=>"active", "locked"=>false, "avatar_url"=>"https://gitlab.com/uploads/-/system/user/avatar/2324599/avatar.png", "web_url"=>"https://gitlab.com/gitlab-release-tools-bot"}, "started_at"=>"2023-10-27T17:29:13.728Z", "finished_at"=>"2023-10-27T17:39:05.280Z", "committed_at"=>nil, "duration"=>592, "queued_duration"=>2, "coverage"=>nil, "detailed_status"=>{"icon"=>"status_success", "text"=>"Passed", "label"=>"passed", "group"=>"success", "tooltip"=>"passed", "has_details"=>true, "details_path"=>"/gitlab-org/security/www-gitlab-com/-/pipelines/1052441157", "illustration"=>nil, "favicon"=>"/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"}}, "diff_refs"=>{"base_sha"=>"eb9089115060a04fc21ab5ff628246e8e809ea9e", "head_sha"=>"215e9e66422d1fb3db1d558b8f432242b71f8669", "start_sha"=>"a5d3cc7e8f09408c9ac120b13f37495f4256cad0"}, "merge_error"=>nil, "user"=>{"can_merge"=>true}}}
[2] pry(main)> ReleaseTools::Security::Publish::MoveBlogPost.new.execute
=> nil
[3] pry(main)> 2023-11-03 08:58:23.771408 D ReleaseTools::GitlabClient -- [HTTParty] [2023-11-03 08:58:23 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fwww-gitlab-com/merge_requests" -
2023-11-03 08:58:23.772303 I ReleaseTools::Security::Publish::MoveBlogPost -- Moving security blog post to canonical -- {:merge_request=>164, :url=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/164"}

Author Check-list

  • Has documentation been updated?
Edited by Steve Abrams

Merge request reports