From 3d06704969660f8c162b48e1d1c960ad855f56c1 Mon Sep 17 00:00:00 2001 From: Lukasz Gornicki Date: Tue, 12 Nov 2024 13:02:32 +0100 Subject: [PATCH 1/3] ci: update global replication for maintainers workflow (#322) --- .github/workflows/global-replicator.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/global-replicator.yml b/.github/workflows/global-replicator.yml index bbb51f6d..dbeb0cc0 100644 --- a/.github/workflows/global-replicator.yml +++ b/.github/workflows/global-replicator.yml @@ -222,7 +222,7 @@ jobs: # Maintainers cannot opt out for any reason except technical ones. replicate_update_maintainers_workflow: if: startsWith(github.repository, 'asyncapi/') - name: Replicate update-maintainers-trigger.yml workflow in the required repositories + name: Replicate update-maintainers-trigger.yaml workflow in the required repositories runs-on: ubuntu-latest steps: - name: Checkout repository @@ -231,9 +231,9 @@ jobs: uses: derberg/manage-files-in-multiple-repositories@beecbe897cf5ed7f3de5a791a3f2d70102fe7c25 with: github_token: ${{ secrets.GH_TOKEN }} - patterns_to_include: .github/workflows/update-maintainers-trigger.yml + patterns_to_include: .github/workflows/update-maintainers-trigger.yaml repos_to_ignore: community,shape-up-process # community repo is ignored as it has its own version of this workflow, version that is triggered by this workflow committer_username: asyncapi-bot committer_email: info@asyncapi.io - commit_message: "ci: update update-maintainers-trigger.yml workflow from global .github repo" + commit_message: "ci: update update-maintainers-trigger.yaml workflow from global .github repo" bot_branch_name: bot/update-files-from-global-repo From 30f9052700a2e9dc9cfb9aca54c0af9afe19c6c8 Mon Sep 17 00:00:00 2001 From: Ashish Padhy Date: Mon, 17 Feb 2025 15:58:58 +0530 Subject: [PATCH 2/3] ci: fix co-authors with pagination (#327) --- .../automerge-for-humans-merging.yml | 81 ++++++++++++++----- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/.github/workflows/automerge-for-humans-merging.yml b/.github/workflows/automerge-for-humans-merging.yml index 9ba0be90..8f193aab 100644 --- a/.github/workflows/automerge-for-humans-merging.yml +++ b/.github/workflows/automerge-for-humans-merging.yml @@ -18,30 +18,69 @@ on: jobs: automerge-for-humans: - if: github.event.pull_request.draft == false && (github.event.pull_request.user.login != 'asyncapi-bot' || github.event.pull_request.user.login != 'dependabot[bot]' || github.event.pull_request.user.login != 'dependabot-preview[bot]') #it runs only if PR actor is not a bot, at least not a bot that we know + # it runs only if PR actor is not a bot, at least not a bot that we know + if: | + github.event.pull_request.draft == false && + (github.event.pull_request.user.login != 'asyncapi-bot' || + github.event.pull_request.user.login != 'dependabot[bot]' || + github.event.pull_request.user.login != 'dependabot-preview[bot]') runs-on: ubuntu-latest steps: - - name: Get list of authors - uses: sergeysova/jq-action@v2 + - name: Get PR authors id: authors + uses: actions/github-script@v7 with: - # This cmd does following (line by line): - # 1. CURL querying the list of commits of the current PR via GH API. Why? Because the current event payload does not carry info about the commits. - # 2. Iterates over the previous returned payload, and creates an array with the filtered results (see below) so we can work wit it later. An example of payload can be found in https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-example-34. - # 3. Grabs the data we need for adding the `Co-authored-by: ...` lines later and puts it into objects to be used later on. - # 4. Filters the results by excluding the current PR sender. We don't need to add it as co-author since is the PR creator and it will become by default the main author. - # 5. Removes repeated authors (authors can have more than one commit in the PR). - # 6. Builds the `Co-authored-by: ...` lines with actual info. - # 7. Transforms the array into plain text. Thanks to this, the actual stdout of this step can be used by the next Workflow step (wich is basically the automerge). - cmd: | - curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" "${{github.event.pull_request._links.commits.href}}?per_page=100" | - jq -r '[.[] - | {name: .commit.author.name, email: .commit.author.email, login: .author.login}] - | map(select(.login != "${{github.event.pull_request.user.login}}")) - | unique - | map("Co-authored-by: " + .name + " <" + .email + ">") - | join("\n")' - multiline: true + script: | + // Get paginated list of all commits in the PR + try { + const commitOpts = github.rest.pulls.listCommits.endpoint.merge({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + const commits = await github.paginate(commitOpts); + return commits; + } catch (error) { + core.setFailed(error.message); + return []; + } + + - name: Create commit message + id: create-commit-message + uses: actions/github-script@v7 + with: + script: | + const commits = ${{ steps.authors.outputs.result }}; + + if (commits.length === 0) { + core.setFailed('No commits found in the PR'); + return ''; + } + + // Get unique authors from the commits list + const authors = commits.reduce((acc, commit) => { + const username = commit.author?.login || commit.commit.author?.name; + if (username && !acc[username]) { + acc[username] = { + name: commit.commit.author?.name, + email: commit.commit.author?.email, + } + } + + return acc; + }, {}); + + // Create a string of the form "Co-authored-by: Name " + // ref: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors + const coAuthors = Object.values(authors).map(author => { + return `Co-authored-by: ${author.name} <${author.email}>`; + }).join('\n'); + + core.debug(coAuthors);; + + return coAuthors; + - name: Automerge PR uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6 env: @@ -50,6 +89,6 @@ jobs: MERGE_METHOD: "squash" # Using the output of the previous step (`Co-authored-by: ...` lines) as commit description. # Important to keep 2 empty lines as https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line mentions - MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ steps.authors.outputs.value }}" + MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ fromJSON(steps.create-commit-message.outputs.result) }}" MERGE_RETRIES: "20" MERGE_RETRY_SLEEP: "30000" From 046cb0f8360677b00aa5cf34ccd72840dd9332bf Mon Sep 17 00:00:00 2001 From: Souvik De Date: Thu, 27 Feb 2025 13:46:37 -0500 Subject: [PATCH 3/3] ci: add command for transferring issue (#314) Co-authored-by: souvik --- .github/workflows/global-replicator.yml | 2 +- .github/workflows/help-command.yml | 3 +- .github/workflows/transfer-issue.yml | 57 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/transfer-issue.yml diff --git a/.github/workflows/global-replicator.yml b/.github/workflows/global-replicator.yml index dbeb0cc0..d5fac1a9 100644 --- a/.github/workflows/global-replicator.yml +++ b/.github/workflows/global-replicator.yml @@ -138,7 +138,7 @@ jobs: uses: derberg/manage-files-in-multiple-repositories@beecbe897cf5ed7f3de5a791a3f2d70102fe7c25 with: github_token: ${{ secrets.GH_TOKEN }} - patterns_to_include: .github/workflows/scripts,.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml,.github/workflows/add-good-first-issue-labels.yml,.github/workflows/automerge-for-humans-merging.yml,.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml,.github/workflows/automerge-orphans.yml,.github/workflows/automerge.yml,.github/workflows/autoupdate.yml,.github/workflows/help-command.yml,.github/workflows/issues-prs-notifications.yml,.github/workflows/lint-pr-title.yml,.github/workflows/notify-tsc-members-mention.yml,.github/workflows/stale-issues-prs.yml,.github/workflows/welcome-first-time-contrib.yml,.github/workflows/release-announcements.yml,.github/workflows/bounty-program-commands.yml,.github/workflows/please-take-a-look-command.yml,.github/workflows/update-pr.yml + patterns_to_include: .github/workflows/scripts,.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml,.github/workflows/add-good-first-issue-labels.yml,.github/workflows/automerge-for-humans-merging.yml,.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml,.github/workflows/automerge-orphans.yml,.github/workflows/automerge.yml,.github/workflows/autoupdate.yml,.github/workflows/help-command.yml,.github/workflows/issues-prs-notifications.yml,.github/workflows/lint-pr-title.yml,.github/workflows/notify-tsc-members-mention.yml,.github/workflows/stale-issues-prs.yml,.github/workflows/welcome-first-time-contrib.yml,.github/workflows/release-announcements.yml,.github/workflows/bounty-program-commands.yml,.github/workflows/please-take-a-look-command.yml,.github/workflows/update-pr.yml,.github/workflows/transfer-issue.yml committer_username: asyncapi-bot committer_email: info@asyncapi.io commit_message: "ci: update of files from global .github repo" diff --git a/.github/workflows/help-command.yml b/.github/workflows/help-command.yml index 3f4dcbc4..12f5a94c 100644 --- a/.github/workflows/help-command.yml +++ b/.github/workflows/help-command.yml @@ -58,5 +58,6 @@ jobs: At the moment the following comments are supported in issues: - \`/good-first-issue {js | ts | java | go | docs | design | ci-cd}\` or \`/gfi {js | ts | java | go | docs | design | ci-cd}\` - label an issue as a \`good first issue\`. - example: \`/gfi js\` or \`/good-first-issue ci-cd\`` + example: \`/gfi js\` or \`/good-first-issue ci-cd\` + - \`/transfer-issue {repo-name}\` or \`/ti {repo-name}\` - transfer issue from the source repository to the other repository passed by the user. example: \`/ti cli\` or \`/transfer-issue cli\`.` }) \ No newline at end of file diff --git a/.github/workflows/transfer-issue.yml b/.github/workflows/transfer-issue.yml new file mode 100644 index 00000000..06cb1ed9 --- /dev/null +++ b/.github/workflows/transfer-issue.yml @@ -0,0 +1,57 @@ +# This action is centrally managed in https://github.com/asyncapi/.github/ +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo + +name: Transfer Issues between repositories + +on: + issue_comment: + types: + - created + +jobs: + transfer: + if: ${{(!github.event.issue.pull_request && github.event.issue.state != 'closed' && github.actor != 'asyncapi-bot') && (startsWith(github.event.comment.body, '/transfer-issue') || startsWith(github.event.comment.body, '/ti'))}} + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Extract Input + id: extract_step + run: | + COMMENT="${{github.event.comment.body}}" + REPO=$(echo $COMMENT | awk '{print $2}') + echo repo=$REPO >> $GITHUB_OUTPUT + - name: Check Repo + uses: actions/github-script@v7 + with: + github-token: ${{secrets.GH_TOKEN}} + script: | + const r = "${{github.repository}}" + const [owner, repo] = r.split('/') + const repoToMove = process.env.REPO_TO_MOVE + const issue_number = context.issue.number + try { + const {data} = await github.rest.repos.get({ + owner, + repo: repoToMove + }) + }catch (e) { + const body = `${repoToMove} is not a repo under ${owner}. You can only transfer issue to repos that belong to the same organization.` + await github.rest.issues.createComment({ + owner, + repo, + issue_number, + body + }) + process.exit(1) + } + env: + REPO_TO_MOVE: ${{steps.extract_step.outputs.repo}} + - name: Transfer Issue + id: transferIssue + working-directory: ./ + run: | + gh issue transfer ${{github.event.issue.number}} asyncapi/${{steps.extract_step.outputs.repo}} + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} +