-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: support labels copier #207
Conversation
…blt-actions into feature/labels-mergify * 'feature/labels-mergify' of https://github.com/elastic/oblt-actions: Update mergify/labels-copier/README.md
mergify/labels-copier/copy.sh
Outdated
add_label() { | ||
local label=$1 | ||
local pr_url=$2 | ||
|
||
if [ "$DRY_RUN" == "true" ]; then | ||
echo ">> [dry-run]: $label will be added" | ||
else | ||
gh pr edit --add-label "$label" "$pr_url" | ||
fi | ||
} |
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.
you can make it on Action Script in the workflow directly
uses: actions/github-script@v7
env:
labels: ${{ inputs.labels }}
issue: ${{ inputs.issue }}
with:
script: |
const labels = process.env.labels.split(',')
if (labels.length > 0) {
github.rest.issues.addLabels({
issue_number: process.env.issue,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labels,
})
}
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.
I prefer the shell script as I was able to run it locally and test it quickly. In your snippet, I need to add also support for the exclude labels .
What's the reason you want to use the type-script approach?
} | ||
|
||
|
||
pr_number=$(gh pr view --json body -q ".body" "$PR_URL" | sed -n -e '/automatic backport of pull request/,/done/p' | cut -d"#" -f2 | cut -d" " -f1) |
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.
Is there any other way to avoid parsing the body?
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.
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.
And also in the PR title

That's something configured at https://github.com/elastic/apm-server/blob/ac892161040578cf3b10ab77662cd39d6b5b7c8c/.mergify.yml#L72
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.
This code get the label of a PR
const { data } = await github.rest.issues.listLabelsOnIssue({
issue_number: process.env.issue,
owner: context.repo.owner,
repo: context.repo.repo,
})
mergify/labels-copier/copy.sh
Outdated
gh pr view --json labels -q '.labels[]|.name' ${REPOSITORY_URL}/pull/$pr_number | while read label ; do | ||
if [[ -z "$labels" ]] || [[ ",$labels," =~ ",$label," ]]; then | ||
if [[ -n "$EXCLUDED_LABEL" ]] && [[ $label =~ $EXCLUDED_LABEL ]]; then | ||
echo ">> $label is excluded and will not be added since matches '$EXCLUDED_LABEL'" | ||
else | ||
add_label "$label" "$PR_URL" | ||
fi | ||
fi | ||
for additional_label in $(echo $ADDITIONAL_LABELS | sed "s/,/ /g") ; do | ||
add_label "$additional_label" "$PR_URL" | ||
done | ||
done |
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.
it is complex. You can use Action script to add the labels directly, duplicated labels will not apply
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.
It's not that complex IMO. I can simplify it a bit.
And still, I see a much powerful feature to use a shell script, so I can test it out in isolation locally than using the github-script
action step, it's hard to test it locally
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.
Took some bits and pieces from https://github.com/Mergifyio/gha-mergify-merge-queue-labels-copier