Skip to content

Commit

Permalink
Merge master into dependabot/npm_and_yarn/modelina-cli/cross-spawn-7.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
asyncapi-bot-eve authored Feb 17, 2025
2 parents c27eb31 + b38dd6c commit d6afeac
Showing 1 changed file with 60 additions and 21 deletions.
81 changes: 60 additions & 21 deletions .github/workflows/automerge-for-humans-merging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <email>"
// 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:
Expand All @@ -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"

0 comments on commit d6afeac

Please sign in to comment.