-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: implemment pagination #266
Open
Gmin2
wants to merge
6
commits into
asyncapi:master
Choose a base branch
from
Gmin2:co-commit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6a98c15
implemment pagination
Gmin2 a4bda30
added the co-authored by to next line
Gmin2 7873214
done the reviewed changes
Gmin2 322078e
cleanup
Gmin2 efbeb9d
removed `install dependencies` strep
Gmin2 1e5f6c1
Merge branch 'master' into co-commit
derberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||||||||||||||||||||||||||||
# 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 | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# Purpose of this workflow is to allow people to merge PR without a need of maintainer doing it. If all checks are in place (including maintainers approval) - JUST MERGE IT! | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
name: Automerge For Humans | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
on: | ||||||||||||||||||||||||||||||||
|
@@ -18,30 +19,62 @@ 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 | ||||||||||||||||||||||||||||||||
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: Checkout code | ||||||||||||||||||||||||||||||||
uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
- name: Setup Node.js | ||||||||||||||||||||||||||||||||
uses: actions/setup-node@v4 | ||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||
node-version: '20' | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
- name: Get List of 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: | | ||||||||||||||||||||||||||||||||
Gmin2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
async function getCoAuthors() { | ||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||
const commitsResponse = await github.paginate("GET /repos/{owner}/{repo}/pulls/{pull_number}/commits", { | ||||||||||||||||||||||||||||||||
owner: repository.split('/')[0], | ||||||||||||||||||||||||||||||||
repo: repository.split('/')[1], | ||||||||||||||||||||||||||||||||
pull_number: ${{ github.event.number }}, | ||||||||||||||||||||||||||||||||
per_page: 100, | ||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||
Comment on lines
+46
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplification and correction of the way to access the repo information:
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
const authors = commitsResponse | ||||||||||||||||||||||||||||||||
.map(data => ({ | ||||||||||||||||||||||||||||||||
name: data.commit.author.name, | ||||||||||||||||||||||||||||||||
email: data.commit.author.email, | ||||||||||||||||||||||||||||||||
login: data.commit.author.login, | ||||||||||||||||||||||||||||||||
})) | ||||||||||||||||||||||||||||||||
.filter(author => author.email !== commitsResponse[0].commit.author.email) | ||||||||||||||||||||||||||||||||
.reduce((uniqueAuthors, author) => { | ||||||||||||||||||||||||||||||||
if (!uniqueAuthors.some(a => a.email === author.email)) { | ||||||||||||||||||||||||||||||||
uniqueAuthors.push(author); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
return uniqueAuthors; | ||||||||||||||||||||||||||||||||
}, []) | ||||||||||||||||||||||||||||||||
.map(author => `Co-authored-by: ${author.name} <${author.email}>`) | ||||||||||||||||||||||||||||||||
.join('\n'); | ||||||||||||||||||||||||||||||||
console.log(authors); | ||||||||||||||||||||||||||||||||
return authors; | ||||||||||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||||||||||
console.error('Error fetching commits:', error); | ||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
await getCoAuthors(); | ||||||||||||||||||||||||||||||||
Comment on lines
+75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct way to set the output in the
|
await getCoAuthors(); | |
const coAuthors = await getCoAuthors(); | |
core.setOutput("value", coAuthors); |
KhudaDad414 marked this conversation as resolved.
Show resolved
Hide resolved
KhudaDad414 marked this conversation as resolved.
Show resolved
Hide resolved
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.