From 1b88758c0f6a15bb42d1693199dbaddb96b01d8a Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 08:41:28 +0000 Subject: [PATCH 01/20] test12345 --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index 2c931ef..9088179 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -80,7 +80,7 @@ class RubocopAnalysis puts "rubocop_exec" @report = `rubocop --format json` - puts "rubocop format json" + puts "rubocop check_run_script.rb format json" @output = JSON.parse @report annotations, conclusion = analysis_annotation_conclusion(@output) -- Gitee From bbf38901a08de630a2cae1e76dee69f1deb20d4a Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 09:19:47 +0000 Subject: [PATCH 02/20] test --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index 9088179..5dc99db 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -79,7 +79,7 @@ class RubocopAnalysis progress_check_run puts "rubocop_exec" - @report = `rubocop --format json` + #@report = `rubocop --format json` puts "rubocop check_run_script.rb format json" @output = JSON.parse @report -- Gitee From e3f9f9018b725dcc83f05441bfcc58e6315eab6d Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 09:27:20 +0000 Subject: [PATCH 03/20] finished --- check_run_script.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index 5dc99db..cf526ff 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -43,11 +43,14 @@ class RubocopAnalysis def analysis_annotation_conclusion(output) puts "analysis_annotation_conclusion" annotations = [] + max_annotations = 20 conclusion = 'success' annotation_level_list = {"warning" => "warning", "error" => "failure", "fatal" => "failure"} output['files'].each do |file| file['offenses'].each do |offense| + next if max_annotations == 0 + max_annotations -= 1 conclusion = "failure" if conclusion == 'success' && ["error", "fatal"].include?(offense["severity"]) start_line = offense['location']['start_line'] end_line = offense['location']['last_line'] @@ -79,8 +82,8 @@ class RubocopAnalysis progress_check_run puts "rubocop_exec" - #@report = `rubocop --format json` - puts "rubocop check_run_script.rb format json" + @report = `rubocop --format json` + puts "rubocop format json" @output = JSON.parse @report annotations, conclusion = analysis_annotation_conclusion(@output) @@ -99,7 +102,7 @@ class RubocopAnalysis title: 'Octo RuboCop', summary: summary, text: text, - annotations: annotations[1..50] + annotations: annotations } } puts "#{url}" -- Gitee From 78876d87827384567a3f72b7dbd0e2dede9e02fc Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 09:28:52 +0000 Subject: [PATCH 04/20] rescue --- check_run_script.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index cf526ff..4bcd2f0 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -106,8 +106,12 @@ class RubocopAnalysis } } puts "#{url}" - response = RestClient.patch url, data - puts response + begin + response = RestClient.patch url, data + puts response + rescue => e + puts "finished rescue error: #{3}" + end end end -- Gitee From 26b086ebe4b196838ac06bd87841d92e71223cce Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 09:31:05 +0000 Subject: [PATCH 05/20] rescue->e --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index 4bcd2f0..018f200 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -110,7 +110,7 @@ class RubocopAnalysis response = RestClient.patch url, data puts response rescue => e - puts "finished rescue error: #{3}" + puts "finished rescue error: #{e}" end end end -- Gitee From 647d0cef30b8b0471c1e9e520bfcc2e0bd0294e9 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 09:33:02 +0000 Subject: [PATCH 06/20] ey --- check_run_script.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index 018f200..4f3b006 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -105,11 +105,12 @@ class RubocopAnalysis annotations: annotations } } - puts "#{url}" begin response = RestClient.patch url, data puts response rescue => e + puts "#{url}" + puts "#{data}" puts "finished rescue error: #{e}" end end -- Gitee From 4e4c560797118e8a0ca90cf58a0ad977b547c8c4 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 09:46:30 +0000 Subject: [PATCH 07/20] try --- check_run_script.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index 4f3b006..ef50635 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -20,11 +20,10 @@ class RubocopAnalysis data = { details_url: 'https://gitee.com/liwen', name: 'liwen_rubocop', - access_token: @access_token, head_sha: @head_sha } url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs" - @response_json = RestClient.post url, data + @response_json = RestClient.post url, data, {'Private-Token' => @access_token} @response = JSON.parse(@response_json) @check_run_id = @response['id'] puts "@check_run_id => #{@check_run_id}" @@ -34,10 +33,9 @@ class RubocopAnalysis puts "progress_check_run" url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs/#{@check_run_id}" data = { - access_token: @access_token, status: 'in_progress' } - RestClient.patch url, data + RestClient.patch url, data, {'Private-Token' => @access_token} end def analysis_annotation_conclusion(output) @@ -83,19 +81,15 @@ class RubocopAnalysis puts "rubocop_exec" @report = `rubocop --format json` - puts "rubocop format json" @output = JSON.parse @report annotations, conclusion = analysis_annotation_conclusion(@output) - puts "summary" summary = "Octo RuboCop summary\n-Offense count: #{@output['summary']['offense_count']}\n-File count: #{@output['summary']['target_file_count']}\n-Target file count: #{@output['summary']['inspected_file_count']}" text = "Octo RuboCop version: #{@output['metadata']['rubocop_version']}" url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs/#{@check_run_id}" - puts "data" data = { - access_token: @access_token, conclusion: conclusion, details_url: "https://gitee.com/liwen", output: { @@ -106,7 +100,7 @@ class RubocopAnalysis } } begin - response = RestClient.patch url, data + response = RestClient.patch url, data, {'Private-Token' => @access_token} puts response rescue => e puts "#{url}" -- Gitee From b20b46bcfc3415da28cc5f81fdba112130c9bc08 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 15:09:12 +0000 Subject: [PATCH 08/20] to_json --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index ef50635..5d08ed1 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -100,7 +100,7 @@ class RubocopAnalysis } } begin - response = RestClient.patch url, data, {'Private-Token' => @access_token} + response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} puts response rescue => e puts "#{url}" -- Gitee From 94d8a61fe144d2022c17fa76b6eef21bd48152b8 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 15:15:06 +0000 Subject: [PATCH 09/20] finished --- check_run_script.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index 5d08ed1..deba360 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -32,10 +32,9 @@ class RubocopAnalysis def progress_check_run puts "progress_check_run" url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs/#{@check_run_id}" - data = { - status: 'in_progress' - } - RestClient.patch url, data, {'Private-Token' => @access_token} + data = { status: 'in_progress' } + response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} + puts "progress_check_run => #{response}" end def analysis_annotation_conclusion(output) @@ -100,8 +99,8 @@ class RubocopAnalysis } } begin - response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} - puts response + response = RestClient.patch url, data, {'Private-Token' => @access_token} + puts "finished => #{response}" rescue => e puts "#{url}" puts "#{data}" -- Gitee From 91ae82266d8bb0de91c81892633028e039876589 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 15:19:19 +0000 Subject: [PATCH 10/20] finished_to_json --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index deba360..84d3068 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -99,7 +99,7 @@ class RubocopAnalysis } } begin - response = RestClient.patch url, data, {'Private-Token' => @access_token} + response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} puts "finished => #{response}" rescue => e puts "#{url}" -- Gitee From 754f375af7736a436588dfb7a6a1b370547b8528 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 17:11:55 +0000 Subject: [PATCH 11/20] tete --- check_run_script.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index 84d3068..de61ccc 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -48,20 +48,18 @@ class RubocopAnalysis file['offenses'].each do |offense| next if max_annotations == 0 max_annotations -= 1 - conclusion = "failure" if conclusion == 'success' && ["error", "fatal"].include?(offense["severity"]) + start_line = offense['location']['start_line'] end_line = offense['location']['last_line'] start_column = offense['location']['start_column'] end_column = offense['location']['last_column'] message = offense['message'] - path = offense['path'] - annotation_level = annotation_level_list[offense["severity"]] annotation = { - path: path, + path: 'check_run_script.rb', start_line: start_line, end_line: end_line, - annotation_level: annotation_level, + annotation_level: 'notice', message: message } @@ -83,12 +81,15 @@ class RubocopAnalysis @output = JSON.parse @report annotations, conclusion = analysis_annotation_conclusion(@output) + puts "annotations => #{annotations}" + puts "conclusion => #{conclusion}" summary = "Octo RuboCop summary\n-Offense count: #{@output['summary']['offense_count']}\n-File count: #{@output['summary']['target_file_count']}\n-Target file count: #{@output['summary']['inspected_file_count']}" text = "Octo RuboCop version: #{@output['metadata']['rubocop_version']}" url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs/#{@check_run_id}" data = { + status: 'completed', conclusion: conclusion, details_url: "https://gitee.com/liwen", output: { @@ -98,14 +99,8 @@ class RubocopAnalysis annotations: annotations } } - begin - response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} - puts "finished => #{response}" - rescue => e - puts "#{url}" - puts "#{data}" - puts "finished rescue error: #{e}" - end + response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} + puts "finished => #{response}" end end -- Gitee From d0f6795ebfcecba46c91969d47193e34151876a2 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 17:38:11 +0000 Subject: [PATCH 12/20] testtt --- check_run_script.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index de61ccc..4af45d4 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -70,7 +70,7 @@ class RubocopAnalysis annotations.push(annotation) end end - [annotations, conclusion] + annotations end def rubocop_exec @@ -80,25 +80,23 @@ class RubocopAnalysis @report = `rubocop --format json` @output = JSON.parse @report - annotations, conclusion = analysis_annotation_conclusion(@output) - puts "annotations => #{annotations}" - puts "conclusion => #{conclusion}" + annotations = analysis_annotation_conclusion(@output) summary = "Octo RuboCop summary\n-Offense count: #{@output['summary']['offense_count']}\n-File count: #{@output['summary']['target_file_count']}\n-Target file count: #{@output['summary']['inspected_file_count']}" text = "Octo RuboCop version: #{@output['metadata']['rubocop_version']}" url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs/#{@check_run_id}" data = { - status: 'completed', - conclusion: conclusion, + conclusion: 'success', details_url: "https://gitee.com/liwen", output: { title: 'Octo RuboCop', - summary: summary, - text: text, + summary: summary || "test summary", + text: "Octo RuboCop version: #{@output['metadata']['rubocop_version']}" || "text test", annotations: annotations } } + puts "data" response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} puts "finished => #{response}" end -- Gitee From 1730142b0391f6714071c4b3eaf5193eb58a4948 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 17:45:41 +0000 Subject: [PATCH 13/20] tettttt --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index 4af45d4..3a0f4b9 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -111,4 +111,4 @@ else puts str RubocopAnalysis.new(str).exec end -end \ No newline at end of file +end -- Gitee From b2e84cc27ef6e758ab77af652023e7e9d60fc849 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 17:53:56 +0000 Subject: [PATCH 14/20] finished --- check_run_script.rb | 126 ++++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index 3a0f4b9..aa70408 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -12,7 +12,7 @@ class RubocopAnalysis def exec puts "#{@repo}, #{@access_token}, #{@head_sha}" create_rubocop - rubocop_exec + initiate_check_run end def create_rubocop @@ -29,78 +29,92 @@ class RubocopAnalysis puts "@check_run_id => #{@check_run_id}" end - def progress_check_run - puts "progress_check_run" + def initiate_check_run url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs/#{@check_run_id}" - data = { status: 'in_progress' } - response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} - puts "progress_check_run => #{response}" - end + data = { + access_token: @access_token, + status: 'in_progress' + } + repos = RestClient.patch url, data, {content_type: :json, accept: :json} + puts "in_progress: #{repos}" + + + @report = `rubocop '#{repository}' --format json` + @output = JSON.parse @report - def analysis_annotation_conclusion(output) - puts "analysis_annotation_conclusion" annotations = [] - max_annotations = 20 - conclusion = 'success' - annotation_level_list = {"warning" => "warning", "error" => "failure", "fatal" => "failure"} - output['files'].each do |file| - - file['offenses'].each do |offense| - next if max_annotations == 0 - max_annotations -= 1 - - start_line = offense['location']['start_line'] - end_line = offense['location']['last_line'] - start_column = offense['location']['start_column'] - end_column = offense['location']['last_column'] - message = offense['message'] - - annotation = { - path: 'check_run_script.rb', - start_line: start_line, - end_line: end_line, - annotation_level: 'notice', - message: message - } - - if start_line == end_line - annotation.merge(start_column: start_column, end_column: end_column) + # You can create a maximum of 50 annotations per request to the Checks + # API. To add more than 50 annotations, use the "Update a check run" API + # endpoint. This example code limits the number of annotations to 50. + # See /rest/reference/checks#update-a-check-run + # for details. + max_annotations = 50 + + # RuboCop reports the number of errors found in "offense_count" + if @output['summary']['offense_count'] == 0 + conclusion = 'success' + else + conclusion = 'success' + # conclusion = 'failure' + @output['files'].each do |file| + # Only parse offenses for files in this app's repository + file_path = file['path'] + annotation_level = 'notice' + + # Parse each offense to get details and location + file['offenses'].each do |offense| + # Limit the number of annotations to 50 + next if max_annotations == 0 + + max_annotations -= 1 + + start_line = offense['location']['start_line'] + end_line = offense['location']['last_line'] + start_column = offense['location']['start_column'] + end_column = offense['location']['last_column'] + message = offense['message'] + + # Create a new annotation for each error + annotation = { + path: file_path, + start_line: start_line, + end_line: end_line, + annotation_level: annotation_level, + message: message + } + # Annotations only support start and end columns on the same line + if start_line == end_line + annotation.merge(start_column: start_column, end_column: end_column) + end + + annotations.push(annotation) end - - annotations.push(annotation) end end - annotations - end - - def rubocop_exec - progress_check_run - puts "rubocop_exec" - - @report = `rubocop --format json` - @output = JSON.parse @report - - annotations = analysis_annotation_conclusion(@output) + # Updated check run summary and text parameters summary = "Octo RuboCop summary\n-Offense count: #{@output['summary']['offense_count']}\n-File count: #{@output['summary']['target_file_count']}\n-Target file count: #{@output['summary']['inspected_file_count']}" text = "Octo RuboCop version: #{@output['metadata']['rubocop_version']}" + # Mark the check run as complete! And if there are warnings, share them. url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs/#{@check_run_id}" data = { - conclusion: 'success', + access_token: @access_token, + conclusion: "failure", details_url: "https://gitee.com/liwen", - output: { + repos = output: { title: 'Octo RuboCop', - summary: summary || "test summary", - text: "Octo RuboCop version: #{@output['metadata']['rubocop_version']}" || "text test", + summary: summary, + text: text, annotations: annotations } } - puts "data" - response = RestClient.patch url, data.to_json, {'Private-Token' => @access_token} - puts "finished => #{response}" + puts "summary: #{summary}, text: #{text}" + puts "data: #{annotations}" + repos = RestClient.patch url, data, {content_type: :json, accept: :json} + puts "finished: #{repos}" end -end + inputted_strings = ARGV puts "You inputted: " @@ -111,4 +125,4 @@ else puts str RubocopAnalysis.new(str).exec end -end +end \ No newline at end of file -- Gitee From 2da824442e488f97154b11491c2d7042b5d4f1c5 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 18:03:30 +0000 Subject: [PATCH 15/20] f1 --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index aa70408..7bdedf5 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -102,7 +102,7 @@ class RubocopAnalysis access_token: @access_token, conclusion: "failure", details_url: "https://gitee.com/liwen", - repos = output: { + output: { title: 'Octo RuboCop', summary: summary, text: text, -- Gitee From 3535cb25e6ce4658259fdb7b6dcc9969bf9d7329 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 18:15:52 +0000 Subject: [PATCH 16/20] end --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index 7bdedf5..99576c5 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -114,7 +114,7 @@ class RubocopAnalysis repos = RestClient.patch url, data, {content_type: :json, accept: :json} puts "finished: #{repos}" end - +end inputted_strings = ARGV puts "You inputted: " -- Gitee From bee902266bde57d68ba5966e3818d1f4b1b936e8 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Thu, 4 Nov 2021 18:20:32 +0000 Subject: [PATCH 17/20] fix --- check_run_script.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_run_script.rb b/check_run_script.rb index 99576c5..5aa8418 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -39,7 +39,7 @@ class RubocopAnalysis puts "in_progress: #{repos}" - @report = `rubocop '#{repository}' --format json` + @report = `rubocop --format json` @output = JSON.parse @report annotations = [] -- Gitee From 567ece6d042f7f14147cdb19cb95c6bb1e819ba7 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Fri, 5 Nov 2021 03:38:03 +0000 Subject: [PATCH 18/20] finished --- check_run_script.rb | 71 +++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index 5aa8418..c721b81 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -2,21 +2,20 @@ require 'rest-client' require 'json' class RubocopAnalysis - def initialize(head_sha) + def initialize(head_sha, bare_sha) @repo = "liwen/gitos" @access_token = "2339922d27630f723f566e9a2ace6a6f" @head_sha = head_sha + @bare_sha = bare_sha end def exec - puts "#{@repo}, #{@access_token}, #{@head_sha}" create_rubocop initiate_check_run end def create_rubocop - puts "create_rubocop" data = { details_url: 'https://gitee.com/liwen', name: 'liwen_rubocop', @@ -35,54 +34,50 @@ class RubocopAnalysis access_token: @access_token, status: 'in_progress' } - repos = RestClient.patch url, data, {content_type: :json, accept: :json} - puts "in_progress: #{repos}" + repos = RestClient.patch url, data - @report = `rubocop --format json` + diff_paths = `git diff --name-only #{@head_sha} #{@bare_sha}` + puts "diff_paths: #{diff_paths}" + @report = `rubocop --format json #{diff_paths}` @output = JSON.parse @report annotations = [] - # You can create a maximum of 50 annotations per request to the Checks - # API. To add more than 50 annotations, use the "Update a check run" API - # endpoint. This example code limits the number of annotations to 50. - # See /rest/reference/checks#update-a-check-run - # for details. - max_annotations = 50 - - # RuboCop reports the number of errors found in "offense_count" + if @output['summary']['offense_count'] == 0 conclusion = 'success' else conclusion = 'success' - # conclusion = 'failure' @output['files'].each do |file| - # Only parse offenses for files in this app's repository - file_path = file['path'] - annotation_level = 'notice' + annotation_level_list = { + "warning" => "warning", + "error" => "failure", + "fatal" => "failure" + } - # Parse each offense to get details and location file['offenses'].each do |offense| - # Limit the number of annotations to 50 - next if max_annotations == 0 + next unless annotation_level_list.keys.include?(offense["severity"]) - max_annotations -= 1 + if ["error", "fatal"].include?(offense["severity"]) + conclusion = "failure" + elsif conclusion == 'success' && "warning" == offense["severity"].to_s + conclusion = "neutral" + end - start_line = offense['location']['start_line'] - end_line = offense['location']['last_line'] - start_column = offense['location']['start_column'] - end_column = offense['location']['last_column'] - message = offense['message'] + start_line = offense['location']['start_line'] + end_line = offense['location']['last_line'] + start_column = offense['location']['start_column'] + end_column = offense['location']['last_column'] + message = offense['message'] + annotation_level = annotation_level_list[offense["severity"]] - # Create a new annotation for each error annotation = { - path: file_path, + path: file['path'], start_line: start_line, end_line: end_line, annotation_level: annotation_level, message: message } - # Annotations only support start and end columns on the same line if start_line == end_line annotation.merge(start_column: start_column, end_column: end_column) end @@ -92,11 +87,9 @@ class RubocopAnalysis end end - # Updated check run summary and text parameters summary = "Octo RuboCop summary\n-Offense count: #{@output['summary']['offense_count']}\n-File count: #{@output['summary']['target_file_count']}\n-Target file count: #{@output['summary']['inspected_file_count']}" text = "Octo RuboCop version: #{@output['metadata']['rubocop_version']}" - # Mark the check run as complete! And if there are warnings, share them. url = "https://gitee.com/api/v5/repos/#{@repo}/check-runs/#{@check_run_id}" data = { access_token: @access_token, @@ -109,20 +102,16 @@ class RubocopAnalysis annotations: annotations } } - puts "summary: #{summary}, text: #{text}" - puts "data: #{annotations}" - repos = RestClient.patch url, data, {content_type: :json, accept: :json} - puts "finished: #{repos}" + reposponse = RestClient.patch url, data + puts "finished: #{reposponse}" end end inputted_strings = ARGV -puts "You inputted: " if ARGV.empty? puts "nothing :(" else - inputted_strings.each do |str| - puts str - RubocopAnalysis.new(str).exec - end + head_sha, bare_sha = inputted_strings + puts "head_sha: #{head_sha}, bare_sha: #{bare_sha}" + RubocopAnalysis.new(head_sha, bare_sha).exec end \ No newline at end of file -- Gitee From 4ee36f1ef23de9c566abf0ff021647336ef7ecb0 Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Fri, 5 Nov 2021 04:04:11 +0000 Subject: [PATCH 19/20] update --- check_run_script.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/check_run_script.rb b/check_run_script.rb index c721b81..317618b 100644 --- a/check_run_script.rb +++ b/check_run_script.rb @@ -2,10 +2,12 @@ require 'rest-client' require 'json' class RubocopAnalysis - def initialize(head_sha, bare_sha) + def initialize(repo, head_sha, bare_sha, access_token_str) - @repo = "liwen/gitos" - @access_token = "2339922d27630f723f566e9a2ace6a6f" + @repo = repo + puts "access_token_str: #{access_token_str}" + @access_token = Base64.decode(access_token_str)[0...32] + puts "@access_token: #{@access_token}" @head_sha = head_sha @bare_sha = bare_sha end @@ -111,7 +113,7 @@ inputted_strings = ARGV if ARGV.empty? puts "nothing :(" else - head_sha, bare_sha = inputted_strings - puts "head_sha: #{head_sha}, bare_sha: #{bare_sha}" + repo, head_sha, bare_sha, access_token_str = inputted_strings + puts "repo: #{repo}, head_sha: #{head_sha}, bare_sha: #{bare_sha}" RubocopAnalysis.new(head_sha, bare_sha).exec end \ No newline at end of file -- Gitee From da13b2e87d795b2e61bf9549db27b5441331f23f Mon Sep 17 00:00:00 2001 From: liwen <408815583@qq.com> Date: Tue, 9 Nov 2021 08:52:41 +0000 Subject: [PATCH 20/20] update .workflow/check_run-pipeline.yml. --- .workflow/check_run-pipeline.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.workflow/check_run-pipeline.yml b/.workflow/check_run-pipeline.yml index 2774eb3..cd40c86 100644 --- a/.workflow/check_run-pipeline.yml +++ b/.workflow/check_run-pipeline.yml @@ -8,12 +8,21 @@ stages: steps: - step: build@ruby name: build_ruby_31 - displayName: Ruby 构建 + displayName: Rubocop检测 rubyVersion: 2.6.8 - commands: | - echo `pwd` - echo `ls` - ruby "./check_run_script.rb" + commands: + - Int: + - echo `ruby -v` + - echo `pwd` + - Install RubyENV: + - gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ + - gem install rest-client + - gem install json + - gem install rubocop + - gem install base64 + + - Run Script: + - ruby "./script/rubocop_check.rb" ${AGILE_MODULE_NAME} ${AGILE_SOURCE_REVISION} ${AGILE_REVISION} ${ACCESS_TOKEN} triggers: pr: branches: -- Gitee