Skip to content

Adjust move service to use API instead of Git

Mayra Cabrera requested to merge adjust-move-service-to-use-api into master

What does this MR do and why?

Adjust Move service to use API instead of git

Refactor the CopyMergeRequestToCanonical service to use the move a merge request from a security repository to a canonical one using API calls instead of Git operations. Currently, this service is exclusively used to publish the blog post once the security release is on the final stages.

This refactor was done for multiple reasons:

  • The MoveBlogPost execution failed during the last security release showing some bugginess when the blog post was moved from security to canonical. Details on gitlab-com/gl-infra/delivery#19805 (closed)
  • The handbook repository is quite heavy, and git operations require cloning the repository which is time-consuming.
  • The handbook repositories are out of sync, see gitlab-com/gl-infra/delivery#19742 for details, which made the debugging harder.

The new API calls:

  • Create a branch
  • Retrieve the content of the blog post and create a commit based on it.
  • Create a merge request.

Also the MoveBlogPost was a bit refactored to account for the new architecture of the CopyMergeRequestToCanonical service.

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

Testing

  1. A test security blog post was created https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/169
  2. From console, I first double check the security_blog_merge_request method was referring to the test MR
[1] pry(main)> ReleaseTools::GitlabClient.security_blog_merge_request 
2023-11-07 13:45:27.320721 D ReleaseTools::GitlabClient -- [HTTParty] [2023-11-07 13:45:27 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fwww-gitlab-com/merge_requests" -
=> #<Gitlab::ObjectifiedHash:217140 {hash: {"id"=>261940631, "iid"=>169,
  1. Then, I execute the MoveBlogPost service
[2] pry(main)> ReleaseTools::Security::Publish::MoveBlogPost.new.execute
2023-11-07 14:15:21.624449 I ReleaseTools::Security::Publish::MoveBlogPost -- Moving security blog post to canonical -- {:merge_request=>169, :url=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/169"}
2023-11-07 14:15:21.624516 I ReleaseTools::Security::CopyMergeRequestToCanonical -- Creating merge request in canonical -- {:security_merge_request=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/169"}
2023-11-07 14:15:21.624541 I ReleaseTools::Security::CopyMergeRequestToCanonical -- Creating branch -- {:source_branch=>"test-create-16-5-1--16-4-2--16-3-6-post-canonical", :default_branch=>"master", :project=>gitlab-com/www-gitlab-com}
2023-11-07 14:15:23.068207 I ReleaseTools::Security::CopyMergeRequestToCanonical -- Creating commit -- {:source_branch=>"test-create-16-5-1--16-4-2--16-3-6-post-canonical", :file_path=>"sites/uncategorized/source/releases/posts/2023-10-31-security-release-gitlab-16-5-1--16-4-2--16-3-7-released.html.md"}
2023-11-07 14:15:23.068311 I ReleaseTools::Security::CopyMergeRequestToCanonical -- Fetching content -- {:merge_request=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/169", :file_path=>"sites/uncategorized/source/releases/posts/2023-10-31-security-release-gitlab-16-5-1--16-4-2--16-3-7-released.html.md", :branch=>"test-create-16-5-1--16-4-2--16-3-6-post"}
2023-11-07 14:15:29.576099 I ReleaseTools::Security::CopyMergeRequestToCanonical -- Merge request created -- {:web_url=>"https://gitlab.com/gitlab-com/www-gitlab-com/-/merge_requests/131150"}-
2023-11-07 14:15:30.159634 I ReleaseTools::Security::Publish::MoveBlogPost -- Closing security blog merge request -- {:url=>"https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/169"}

The merge request was created on canonical gitlab-com/www-gitlab-com!131150 (closed) 🎉

Results

header header
The DRAFT status was removed from https://gitlab.com/gitlab-org/security/www-gitlab-com/-/merge_requests/169 Screenshot_2023-11-07_at_13.50.56
The security MR was closed and a note was posted Screenshot_2023-11-07_at_13.52.46

Author Check-list

  • [-] Has documentation been updated?
Edited by Mayra Cabrera

Merge request reports