Skip to content

Commit 79f9930

Browse files
authored
Merge branch 'master' into fix/update-json-path-plus
2 parents 769ab82 + 960f7a1 commit 79f9930

File tree

1 file changed

+60
-21
lines changed

1 file changed

+60
-21
lines changed

.github/workflows/automerge-for-humans-merging.yml

+60-21
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,69 @@ on:
1818

1919
jobs:
2020
automerge-for-humans:
21-
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
21+
# it runs only if PR actor is not a bot, at least not a bot that we know
22+
if: |
23+
github.event.pull_request.draft == false &&
24+
(github.event.pull_request.user.login != 'asyncapi-bot' ||
25+
github.event.pull_request.user.login != 'dependabot[bot]' ||
26+
github.event.pull_request.user.login != 'dependabot-preview[bot]')
2227
runs-on: ubuntu-latest
2328
steps:
24-
- name: Get list of authors
25-
uses: sergeysova/jq-action@v2
29+
- name: Get PR authors
2630
id: authors
31+
uses: actions/github-script@v7
2732
with:
28-
# This cmd does following (line by line):
29-
# 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.
30-
# 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.
31-
# 3. Grabs the data we need for adding the `Co-authored-by: ...` lines later and puts it into objects to be used later on.
32-
# 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.
33-
# 5. Removes repeated authors (authors can have more than one commit in the PR).
34-
# 6. Builds the `Co-authored-by: ...` lines with actual info.
35-
# 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).
36-
cmd: |
37-
curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" "${{github.event.pull_request._links.commits.href}}?per_page=100" |
38-
jq -r '[.[]
39-
| {name: .commit.author.name, email: .commit.author.email, login: .author.login}]
40-
| map(select(.login != "${{github.event.pull_request.user.login}}"))
41-
| unique
42-
| map("Co-authored-by: " + .name + " <" + .email + ">")
43-
| join("\n")'
44-
multiline: true
33+
script: |
34+
// Get paginated list of all commits in the PR
35+
try {
36+
const commitOpts = github.rest.pulls.listCommits.endpoint.merge({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
pull_number: context.issue.number
40+
});
41+
42+
const commits = await github.paginate(commitOpts);
43+
return commits;
44+
} catch (error) {
45+
core.setFailed(error.message);
46+
return [];
47+
}
48+
49+
- name: Create commit message
50+
id: create-commit-message
51+
uses: actions/github-script@v7
52+
with:
53+
script: |
54+
const commits = ${{ steps.authors.outputs.result }};
55+
56+
if (commits.length === 0) {
57+
core.setFailed('No commits found in the PR');
58+
return '';
59+
}
60+
61+
// Get unique authors from the commits list
62+
const authors = commits.reduce((acc, commit) => {
63+
const username = commit.author?.login || commit.commit.author?.name;
64+
if (username && !acc[username]) {
65+
acc[username] = {
66+
name: commit.commit.author?.name,
67+
email: commit.commit.author?.email,
68+
}
69+
}
70+
71+
return acc;
72+
}, {});
73+
74+
// Create a string of the form "Co-authored-by: Name <email>"
75+
// ref: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors
76+
const coAuthors = Object.values(authors).map(author => {
77+
return `Co-authored-by: ${author.name} <${author.email}>`;
78+
}).join('\n');
79+
80+
core.debug(coAuthors);;
81+
82+
return coAuthors;
83+
4584
- name: Automerge PR
4685
uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6
4786
env:
@@ -50,6 +89,6 @@ jobs:
5089
MERGE_METHOD: "squash"
5190
# Using the output of the previous step (`Co-authored-by: ...` lines) as commit description.
5291
# 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
53-
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ steps.authors.outputs.value }}"
92+
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ fromJSON(steps.create-commit-message.outputs.result) }}"
5493
MERGE_RETRIES: "20"
5594
MERGE_RETRY_SLEEP: "30000"

0 commit comments

Comments
 (0)