From 6301c87423132871bee648f6e766b6e8c5239b10 Mon Sep 17 00:00:00 2001 From: lenkan Date: Fri, 18 Oct 2024 11:31:27 +0200 Subject: [PATCH 1/3] workflow for creating issue report --- .github/workflows/create-report.yaml | 28 +++++++ scripts/create-report.sh | 112 +++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 .github/workflows/create-report.yaml create mode 100755 scripts/create-report.sh diff --git a/.github/workflows/create-report.yaml b/.github/workflows/create-report.yaml new file mode 100644 index 0000000..912d997 --- /dev/null +++ b/.github/workflows/create-report.yaml @@ -0,0 +1,28 @@ +name: Create issue and PR report + +on: + workflow_dispatch: + inputs: + days-ago: + type: number + default: 7 + description: The number of days to go back from today + dry-run: + type: boolean + default: false + description: Do not create the discussion item, just print the result +env: + DAYS_AGO: ${{ github.event.inputs.days-ago }} + GH_TOKEN: ${{ github.token }} + REPO_OWNER: ${{ github.repository_owner }} + REPO_NAME: keri + CATEGORY_SLUG: meetings + DRY_RUN: ${{ github.event.inputs.dry-run }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Print report + run: ./scripts/create-report.sh diff --git a/scripts/create-report.sh b/scripts/create-report.sh new file mode 100755 index 0000000..f7b9fdd --- /dev/null +++ b/scripts/create-report.sh @@ -0,0 +1,112 @@ +#!/bin/bash +set -e + +days=${DAYS_AGO:-8} # default to 8 +date=$(date --date="$days days ago" +"%Y-%m-%d") + +repo_owner=${REPO_OWNER:?"REPO_OWNER not set"} +repo_name=${REPO_NAME:?"REPO_NAME not set"} +category_slug=${CATEGORY_SLUG:?"CATEGORY_SLUG not set"} + +repos=( + "WebOfTrust/keripy" + "WebOfTrust/keria" + "WebOfTrust/signify-ts" + "WebOfTrust/signifypy" + "WebOfTrust/cesride" + "WebOfTrust/kerific" + "WebOfTrust/kerisse" + "WebOfTrust/keridoc" + "WebOfTrust/signify-browser-extension" + "WebOfTrust/polaris-web" +) + +function create_report { + for p in "${repos[@]}" + do + issues=$(gh issue list --json url,title --repo "${p}" --search "created:>=$date sort:created-asc is:open" --template \ + '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') + + open_prs=$(gh pr list --json url,title --repo "${p}" --search "created:>=$date sort:created-asc is:open" --template \ + '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') + + merged_prs=$(gh pr list --json url,title --repo "${p}" --search "merged:>=$date sort:created-asc is:merged" --template \ + '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') + + echo "# Repository ${p}" + echo "" + echo "## Issues created after $date" + echo "" + + + if [ -z "$issues" ]; then + echo "No issues found" + else + echo "$issues" + fi + + echo "" + echo "## Pull requests opened after $date" + echo "" + + if [ -z "$open_prs" ]; then + echo "No pull requests found" + else + echo "$open_prs" + fi + + echo "" + echo "## Pull requests merged after $date" + echo "" + + if [ -z "$merged_prs" ]; then + echo "No pull requests found" + else + echo "$merged_prs" + fi + + echo "" + done +} + + +function create_discussion { + title=$1 + body=$2 + + repo_id=$(gh api graphql -q '.data.repository.id' -F owner="$repo_owner" -F name="$repo_name" -f query='query + FindRepository($owner:String!, $name: String!) + { + repository(owner:$owner, name:$name) { + id + } + } + ') + + category_id=$(gh api graphql -q '.data.repository.discussionCategory.id' -F owner="$repo_owner" -F name="$repo_name" -F category="$category_slug" -f query='query + FindCategory($owner:String!, $name:String!, $category: String!) + { + repository(owner:$owner, name:$name) { + discussionCategory(slug:$category) { + id + } + } + } + ') + + gh api graphql -F repoId="$repo_id" -F categoryId="$category_id" -F body="$body" -F title="$title" -f query=' + mutation CreateDiscussion($repoId:ID!, $categoryId:ID!, $body:String!, $title:String!) { + createDiscussion(input: {repositoryId: $repoId, categoryId: $categoryId, body: $body, title: $title}) { + discussion { + id + } + } + } + ' +} + +if [ "${DRY_RUN}" = "true" ]; then + create_report +else + create_discussion "Issues and PR summary $(date +%Y-%m-%d)" "$(create_report)" +fi From 3ef54d071293b698cdf0c855ea32ddca6e969096 Mon Sep 17 00:00:00 2001 From: lenkan Date: Sun, 10 Nov 2024 11:28:07 +0100 Subject: [PATCH 2/3] update to create a comment for each repo --- .github/workflows/create-report.yaml | 6 +- scripts/create-report.sh | 134 +++++++++++++++------------ 2 files changed, 77 insertions(+), 63 deletions(-) diff --git a/.github/workflows/create-report.yaml b/.github/workflows/create-report.yaml index 912d997..8ef5dfa 100644 --- a/.github/workflows/create-report.yaml +++ b/.github/workflows/create-report.yaml @@ -7,17 +7,13 @@ on: type: number default: 7 description: The number of days to go back from today - dry-run: - type: boolean - default: false - description: Do not create the discussion item, just print the result + env: DAYS_AGO: ${{ github.event.inputs.days-ago }} GH_TOKEN: ${{ github.token }} REPO_OWNER: ${{ github.repository_owner }} REPO_NAME: keri CATEGORY_SLUG: meetings - DRY_RUN: ${{ github.event.inputs.dry-run }} jobs: build: diff --git a/scripts/create-report.sh b/scripts/create-report.sh index f7b9fdd..2d85ae6 100755 --- a/scripts/create-report.sh +++ b/scripts/create-report.sh @@ -21,58 +21,56 @@ repos=( "WebOfTrust/polaris-web" ) -function create_report { - for p in "${repos[@]}" - do - issues=$(gh issue list --json url,title --repo "${p}" --search "created:>=$date sort:created-asc is:open" --template \ - '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') - - open_prs=$(gh pr list --json url,title --repo "${p}" --search "created:>=$date sort:created-asc is:open" --template \ - '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') - - merged_prs=$(gh pr list --json url,title --repo "${p}" --search "merged:>=$date sort:created-asc is:merged" --template \ - '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') - - echo "# Repository ${p}" - echo "" - echo "## Issues created after $date" - echo "" - - - if [ -z "$issues" ]; then - echo "No issues found" - else - echo "$issues" - fi - - echo "" - echo "## Pull requests opened after $date" - echo "" - - if [ -z "$open_prs" ]; then - echo "No pull requests found" - else - echo "$open_prs" - fi - - echo "" - echo "## Pull requests merged after $date" - echo "" - - if [ -z "$merged_prs" ]; then - echo "No pull requests found" - else - echo "$merged_prs" - fi - - echo "" - done -} +function create_repo_summary { + repo=$1 + + issues=$(gh issue list --json url,title --repo "${repo}" --search "created:>=$date sort:created-asc is:open" \ + --template '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') + + open_prs=$(gh pr list --json url,title --repo "${repo}" --search "created:>=$date sort:created-asc is:open" \ + --template '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') + + merged_prs=$(gh pr list --json url,title --repo "${repo}" --search "merged:>=$date sort:created-asc is:merged" \ + --template '{{range .}}{{"- "}}{{.url}}{{"\n"}}{{end}}') + + echo "# Repository ${p}" + echo "" + echo "## Issues created after $date" + echo "" + + + if [ -z "$issues" ]; then + echo "No issues found" + else + echo "$issues" + fi + + echo "" + echo "## Pull requests opened after $date" + echo "" + + if [ -z "$open_prs" ]; then + echo "No pull requests found" + else + echo "$open_prs" + fi + echo "" + echo "## Pull requests merged after $date" + echo "" + + if [ -z "$merged_prs" ]; then + echo "No pull requests found" + else + echo "$merged_prs" + fi + + echo "" +} function create_discussion { - title=$1 - body=$2 + title="Issues and PR summary $(date +%Y-%m-%d)" + body="Zoom: https://us06web.zoom.us/j/84721071832" repo_id=$(gh api graphql -q '.data.repository.id' -F owner="$repo_owner" -F name="$repo_name" -f query='query FindRepository($owner:String!, $name: String!) @@ -94,10 +92,29 @@ function create_discussion { } ') - gh api graphql -F repoId="$repo_id" -F categoryId="$category_id" -F body="$body" -F title="$title" -f query=' - mutation CreateDiscussion($repoId:ID!, $categoryId:ID!, $body:String!, $title:String!) { - createDiscussion(input: {repositoryId: $repoId, categoryId: $categoryId, body: $body, title: $title}) { - discussion { + if [ "${DRY_RUN}" = "true" ]; then + echo "$body" + else + gh api graphql -q '.data.createDiscussion.discussion.id' -F repoId="$repo_id" -F categoryId="$category_id" -F body="$body" -F title="$title" -f query=' + mutation CreateDiscussion($repoId:ID!, $categoryId:ID!, $body:String!, $title:String!) { + createDiscussion(input: {repositoryId: $repoId, categoryId: $categoryId, body: $body, title: $title}) { + discussion { + id + } + } + } + ' + fi; +} + +function create_discussion_comment { + discussion_id="$1" + body="$2" + + gh api graphql -F discussionId="$discussion_id" -F body="$body" -f query=' + mutation AddDiscussionComment($discussionId:ID!, $body:String!) { + addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { + comment { id } } @@ -105,8 +122,9 @@ function create_discussion { ' } -if [ "${DRY_RUN}" = "true" ]; then - create_report -else - create_discussion "Issues and PR summary $(date +%Y-%m-%d)" "$(create_report)" -fi +discussion_id=$(create_discussion) + +for p in "${repos[@]}" +do + create_discussion_comment "$discussion_id" "$(create_repo_summary "$p")" +done From 3eb2fe786c75c07945ed8668356c760667e504d0 Mon Sep 17 00:00:00 2001 From: lenkan Date: Sun, 10 Nov 2024 11:34:29 +0100 Subject: [PATCH 3/3] remove dryrun check --- scripts/create-report.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/scripts/create-report.sh b/scripts/create-report.sh index 2d85ae6..ffccaca 100755 --- a/scripts/create-report.sh +++ b/scripts/create-report.sh @@ -92,19 +92,15 @@ function create_discussion { } ') - if [ "${DRY_RUN}" = "true" ]; then - echo "$body" - else - gh api graphql -q '.data.createDiscussion.discussion.id' -F repoId="$repo_id" -F categoryId="$category_id" -F body="$body" -F title="$title" -f query=' - mutation CreateDiscussion($repoId:ID!, $categoryId:ID!, $body:String!, $title:String!) { - createDiscussion(input: {repositoryId: $repoId, categoryId: $categoryId, body: $body, title: $title}) { - discussion { - id - } + gh api graphql -q '.data.createDiscussion.discussion.id' -F repoId="$repo_id" -F categoryId="$category_id" -F body="$body" -F title="$title" -f query=' + mutation CreateDiscussion($repoId:ID!, $categoryId:ID!, $body:String!, $title:String!) { + createDiscussion(input: {repositoryId: $repoId, categoryId: $categoryId, body: $body, title: $title}) { + discussion { + id } } - ' - fi; + } + ' } function create_discussion_comment {