Skip to content

Notify implementation issue when unlinked

Steve Abrams requested to merge delivery19571-unlinked-notify into master

🍔 What does this MR do and why?

We are automating the process of linking/unlinking security implementation issues to security release tracking issues. This MR adds some behavior when an issue is unlinked:

  • A comment is added to the security implementation issue notifying the assignee.
  • The security-target label is removed.

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

🍟 Testing

To test this, I used two fake issues:

I made sure they were linked before starting the test.

I modified my local code to force the security implementation issue to be chosen for unlinking and also to use the fake tracking issue:

git diff
diff --git a/lib/release_tools/security/implementation_issue.rb b/lib/release_tools/security/implementation_issue.rb
index 1947cc7a..33358908 100644
--- a/lib/release_tools/security/implementation_issue.rb
+++ b/lib/release_tools/security/implementation_issue.rb
@@ -54,17 +54,20 @@ module ReleaseTools
       end

       def ready_to_be_processed?
-        if missing_backports?
-          reject('missing merge requests')
-        elsif !merge_requests_with_allowed_status?
-          reject('invalid merge requests status')
-        elsif !merge_requests_assigned_to_the_bot?
-          reject('unassigned merge requests')
-        elsif !valid_merge_requests?
-          reject('invalid merge requests')
-        else
-          true
-        end
+        false
+        # if missing_backports?
+        #   reject('missing merge requests')
+        # elsif !merge_requests_with_allowed_status?
+        #   reject('invalid merge requests status')
+        # elsif !merge_requests_assigned_to_the_bot?
+        #   reject('unassigned merge requests')
+        # elsif !valid_merge_requests?
+        #   reject('invalid merge requests')
+        # else
+        #   true
+        # end
       end

       def reject(reason)
diff --git a/lib/release_tools/security/issue_crawler.rb b/lib/release_tools/security/issue_crawler.rb
index 520d2fda..5245f676 100644
--- a/lib/release_tools/security/issue_crawler.rb
+++ b/lib/release_tools/security/issue_crawler.rb
@@ -12,7 +12,7 @@ module ReleaseTools
       SECURITY_NAMESPACE = 'gitlab-org/security'

       # The label required by security root/meta issues.
-      ROOT_ISSUE_LABEL = 'upcoming security release'
+      ROOT_ISSUE_LABEL = 'security-target'

       # The label required for a related issue or merge request to be considered
       # by the crawler.
@@ -96,7 +96,7 @@ module ReleaseTools
       # Returns issues that are related to the security release tracking issue.
       def related_security_issues
         security_issues_and_merge_requests_for(
-          security_issues_for(release_issue.iid)
+          security_issues_for(424529)
         )
       end

Then I ran the processor locally:

~/workspace/gitlab-org/release-tools (delivery19571-unlinked-notify ✗) RELEASE_BOT_PRODUCTION_TOKEN=REDACTED be pry --gem
[1] pry(main)> ReleaseTools::Security::TargetIssuesProcessor.new.execute
2023-09-13 11:09:15.456770 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:15 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fcharts%2Fcomponents%2Fimages/issues" 2
2023-09-13 11:09:15.764904 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:15 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fgitaly/issues" 2
2023-09-13 11:09:16.072263 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:16 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fgitlab/issues" -
2023-09-13 11:09:16.317391 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:16 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fgitlab-pages/issues" 2
2023-09-13 11:09:16.569934 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:16 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fsecurity%2Fomnibus-gitlab/issues" 2
2023-09-13 11:09:17.220764 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:17 -0600] 200 "GET https://gitlab.com/api/v4/projects/15642544/issues/970/related_merge_requests" -
2023-09-13 11:09:17.620942 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:17 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/issues" -
2023-09-13 11:09:17.623235 W Ruby -- WARNING: Please convert ObjectifiedHash object to hash before calling Hash methods on it.
 -- {:source=>"ruby_warnings", :stacktrace=>"/Users/steveabrams/workspace/gitlab-org/release-tools/lib/release_tools/issuable.rb:6:in `initialize'"}
2023-09-13 11:09:17.624073 I ReleaseTools::Security::TargetIssuesProcessor -- 1 target issues found. They will be evaluated and considered for linking to the security release tracking issue: https://gitlab.com/gitlab-org/gitlab/-/issues/424529.
2023-09-13 11:09:18.752452 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:18 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/issues/424529/links" -
2023-09-13 11:09:19.315211 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:19 -0600] 200 "GET https://gitlab.com/api/v4/projects/15642544/issues/970/related_merge_requests" -
2023-09-13 11:09:19.316316 I ReleaseTools::Security::TargetIssuesProcessor -- https://gitlab.com/gitlab-org/security/gitlab/-/issues/970 will be unlinked from  the security release tracking issue as it is no longer ready to be processed.
2023-09-13 11:09:19.806907 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:19 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/issues" -
2023-09-13 11:09:20.124664 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:20 -0600] 200 "GET https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/issues/424529/links" -
2023-09-13 11:09:20.825550 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:20 -0600] 200 "DELETE https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/issues/424529/links/4286874" -
2023-09-13 11:09:21.416250 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:21 -0600] 201 "POST https://gitlab.com/api/v4/projects/15642544/issues/970/notes" 833
2023-09-13 11:09:22.436073 D ReleaseTools::GitlabClient -- [HTTParty] [2023-09-13 11:09:22 -0600] 200 "PUT https://gitlab.com/api/v4/projects/15642544/issues/970" -
=> [#<ReleaseTools::Security::ImplementationIssue:0x000000010b7dfaf8
  @iid=970,
  @issue=
   #<Gitlab::ObjectifiedHash:217160 {hash: {"id"=>133377103, "iid"=>970, "project_id"=>15642544, "title"=>"TEST - Please disregard", "description"=>"Issue for testing https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/19568", "state"=>"opened", "created_at"=>"2023-09-07T19:45:37.566Z", "updated_at"=>"2023-09-13T17:08:22.386Z", "closed_at"=>nil, "closed_by"=>nil, "labels"=>["security", "security-target", "type::maintenance"], ...>,
  @merge_requests=[],
  @pending_reason=nil,
  @project_id=15642544,
  @reference="gitlab-org/security/gitlab#970",
  @web_url="https://gitlab.com/gitlab-org/security/gitlab/-/issues/970">]

We can see the comment on the issue and the label removed:

Screenshot_2023-09-13_at_11.09.41_AM

Author Check-list

  • [-] Has documentation been updated?
Edited by Steve Abrams

Merge request reports