From 18d1cce99ab30a0f9a2a8ad3285e28b71c7182b8 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 19 Mar 2024 07:40:19 +0000 Subject: [PATCH] ci: remove pr summary workflow --- .github/scripts/.bundle/config | 3 - .github/scripts/.gitignore | 1 - .github/scripts/Gemfile | 8 -- .github/scripts/Gemfile.lock | 29 ----- .github/scripts/github-graphql.rb | 15 --- .github/scripts/pr-summary.rb | 197 ------------------------------ .github/workflows/pr-summary.yaml | 56 --------- 7 files changed, 309 deletions(-) delete mode 100644 .github/scripts/.bundle/config delete mode 100644 .github/scripts/.gitignore delete mode 100644 .github/scripts/Gemfile delete mode 100644 .github/scripts/Gemfile.lock delete mode 100644 .github/scripts/github-graphql.rb delete mode 100644 .github/scripts/pr-summary.rb delete mode 100644 .github/workflows/pr-summary.yaml diff --git a/.github/scripts/.bundle/config b/.github/scripts/.bundle/config deleted file mode 100644 index 43f1a636e..000000000 --- a/.github/scripts/.bundle/config +++ /dev/null @@ -1,3 +0,0 @@ ---- -BUNDLE_PATH: "vendor/bundle" -BUNDLE_WITHOUT: "production" diff --git a/.github/scripts/.gitignore b/.github/scripts/.gitignore deleted file mode 100644 index 61ead8666..000000000 --- a/.github/scripts/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/vendor diff --git a/.github/scripts/Gemfile b/.github/scripts/Gemfile deleted file mode 100644 index 05561b266..000000000 --- a/.github/scripts/Gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } - -gem "graphql-client" -gem "time_ago_in_words" diff --git a/.github/scripts/Gemfile.lock b/.github/scripts/Gemfile.lock deleted file mode 100644 index 8f3b7eb08..000000000 --- a/.github/scripts/Gemfile.lock +++ /dev/null @@ -1,29 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (7.0.4.2) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - concurrent-ruby (1.2.0) - graphql (1.12.14) - graphql-client (0.16.0) - activesupport (>= 3.0) - graphql (~> 1.8) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - minitest (5.17.0) - time_ago_in_words (0.1.1) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) - -PLATFORMS - ruby - -DEPENDENCIES - graphql-client - time_ago_in_words - -BUNDLED WITH - 2.1.4 diff --git a/.github/scripts/github-graphql.rb b/.github/scripts/github-graphql.rb deleted file mode 100644 index ed166c32b..000000000 --- a/.github/scripts/github-graphql.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "graphql/client" -require "graphql/client/http" - -module GitHubGraphQL - HTTP = GraphQL::Client::HTTP.new("https://api.github.com/graphql") do - def headers(context) - { - "User-Agent" => "My Client", - "Authorization" => "bearer #{ENV['GITHUB_TOKEN']}" - } - end - end - Schema = GraphQL::Client.load_schema(HTTP) - Client = GraphQL::Client.new(schema: Schema, execute: HTTP) -end diff --git a/.github/scripts/pr-summary.rb b/.github/scripts/pr-summary.rb deleted file mode 100644 index 2820d1ee9..000000000 --- a/.github/scripts/pr-summary.rb +++ /dev/null @@ -1,197 +0,0 @@ -#!/usr/bin/env ruby - -require 'time_ago_in_words' -require_relative 'github-graphql' - -ReviewRequestsQuery = GitHubGraphQL::Client.parse <<-GRAPHQL -query($query: String!) { - search(query: $query, type: ISSUE, first: 100) { - nodes { - ... on PullRequest { - number - url - title - isDraft - additions - deletions - changedFiles - createdAt - updatedAt - commits { - totalCount - } - reviewDecision - reviewRequests(last: 100) { - nodes { - requestedReviewer { - __typename, - ... on User { - login - } - } - } - } - latestReviews(first:100) { - nodes { - author { - login - } - state - } - } - author { - login - } - } - } - } -} -GRAPHQL - -repo_owner = 'nervosnetwork' -repo_name = 'rfcs' -body = [] - -def pluralize(count, singular, plural) - if count == 1 - "#{count} #{singular}" - else - "#{count} #{plural}" - end -end - -def format_pr(pr) - commits = pluralize(pr.commits.total_count, 'commit', 'commits') - changed_files = pluralize(pr.changed_files, 'file', 'files') - created = Time.parse(pr.created_at).ago_in_words - updated = Time.parse(pr.updated_at).ago_in_words - "#{pr.title} (#{commits}, #{changed_files}, +#{pr.additions}-#{pr.deletions}, created #{created}, last updated #{updated}) #{pr.url}" -end - -def pr_review_state(pr) - states = pr.latest_reviews.nodes.group_by(&:state) - components = [] - if states.include?('APPROVED') - components << "#{states['APPROVED'].size} approved" - end - if states.include?('CHANGES_REQUESTED') - components << "#{states['CHANGES_REQUESTED'].size} requested changes" - end - if states.include?('COMMENTED') - components << "#{states['COMMENTED'].size} commented" - end - if states.include?('DISMISSED') - components << "#{states['DISMISSED'].size} dismissed" - end - if states.include?('PENDING') - components << "#{states['PENDING'].size} pending" - end - - components.join(', ') -end - -def author_link(login, repos) - query = "is:open is:pr author:#{login} #{repos} -review:approved" - "https://github.com/pulls?q=" + URI.encode_www_form_component(query) -end - -def reviewer_link(login, repos) - query = "is:open is:pr review-requested:#{login} #{repos}" - "https://github.com/pulls?q=" + URI.encode_www_form_component(query) -end - -pr_repos = "repo:#{repo_owner}/#{repo_name}" -open_prs = GitHubGraphQL::Client.query(ReviewRequestsQuery, variables: { - query: "#{pr_repos} is:pr is:open sort:created-asc" -}).data.search.nodes - -if open_prs.size > 0 - pending_author_stats = Hash.new {|h, k| h[k] = 0} - pending_reviewers_stats = Hash.new {|h, k| h[k] = 0} - - body << "# Pull Requests (#{open_prs.size})\n" - - ready_to_merge, remaining_prs = open_prs.partition do |pr| - pr.review_decision == 'APPROVED' - end - if ready_to_merge.size > 0 - body << "## Ready To Merge (#{ready_to_merge.size})\n" - ready_to_merge.each do |pr| - body << "- #{pr.author.login} #{pr.title} #{pr.url}" - end - body << '' - end - - pending_author, remaining_prs = remaining_prs.partition do |pr| - pr.is_draft || ( - pr.review_decision == 'CHANGES_REQUESTED' && - pr.latest_reviews.nodes.map(&:state).include?('CHANGES_REQUESTED') - ) - end - if pending_author.size > 0 - body << "## Pending Author (#{pending_author.size})\n" - pending_author.each do |pr| - pending_author_stats[pr.author.login] += 1 - - if pr.is_draft - body << "- **DRAFT**: @#{pr.author.login} #{format_pr(pr)}" - else - body << "- @#{pr.author.login} #{format_pr(pr)}" - review_state = pr_review_state(pr) - if review_state != '' - body << " - #{review_state}" - end - pending_reviewers = pr.review_requests.nodes.map do |node| - node.requested_reviewer.login - end.compact - if pending_reviewers.size > 0 - pending_reviewers.each do |login| - pending_reviewers_stats[login] += 1 - end - body << " - requested reviews from @#{pending_reviewers.join(' @')}" - end - end - end - body << '' - end - - if remaining_prs.size > 0 - body << "## Pending Reviewers (#{remaining_prs.size()})\n" - remaining_prs.each do |pr| - body << "- #{pr.author.login} #{format_pr(pr)}" - review_state = pr_review_state(pr) - if review_state != '' - body << " - #{review_state}" - end - pending_reviewers = pr.review_requests.nodes.map do |node| - node.requested_reviewer&.login - end.compact - if pending_reviewers.size > 0 - pending_reviewers.each do |login| - pending_reviewers_stats[login] += 1 - end - body << " - requested reviews from @#{pending_reviewers.join(' @')}" - end - end - body << '' - end - - if pending_author_stats.size + pending_reviewers_stats.size > 0 - body << "## By Owners\n" - (pending_author_stats.keys + pending_reviewers_stats.keys).uniq.each do |login| - body << "- @#{login}" - if pending_author_stats.include?(login) - body << " - #{pluralize(pending_author_stats[login], 'pr', 'prs')} to update #{author_link(login, pr_repos)}" - end - if pending_reviewers_stats.include?(login) - body << " - #{pluralize(pending_reviewers_stats[login], 'pr', 'prs')} to review #{reviewer_link(login, pr_repos)}" - end - end - body << '' - end - - body << '' -end - -puts body.join("\n") - diff --git a/.github/workflows/pr-summary.yaml b/.github/workflows/pr-summary.yaml deleted file mode 100644 index 9438a7132..000000000 --- a/.github/workflows/pr-summary.yaml +++ /dev/null @@ -1,56 +0,0 @@ -name: Create PR Summary - -on: - schedule: - - cron: '30 0 * * 1' - workflow_dispatch: {} - -jobs: - pr-summary: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-ruby@v1 - with: - ruby-version: 2.7 - - - name: bundle install - run: cd .github/scripts/ && bundle install - - - name: run ruby script - id: summary - run: | - summary="$(cd .github/scripts/ && bundle exec ruby pr-summary.rb)" - summary="${summary//$'%'/%25}" - summary="${summary//$'\n'/%0A}" - summary="${summary//$'\r'/%0D}" - echo "::set-output name=summary::$summary" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: get current date - id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" - - - uses: octokit/graphql-action@v2.x - if: ${{ steps.summary.outputs.summary != '' }} - with: - query: | - mutation createDiscussionWithBody($body: String!) { - createDiscussion(input: { - title: "PR Summary ${{ steps.date.outputs.date }}", - body: $body, - categoryId: "DIC_kwDOB1Oxh84B-hNl", - repositoryId: "MDEwOlJlcG9zaXRvcnkxMjI5MjU0NDc=", - }) { - discussion { - url - } - } - } - body: ${{ toJSON(steps.summary.outputs.summary) }} - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}