Skip to content
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

Label to title #125

Merged
merged 16 commits into from
Aug 14, 2024
51 changes: 51 additions & 0 deletions label-to-title/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Label to Title"
description: "Update the title of an issue or pull request based on the label added or removed."
liamhuber marked this conversation as resolved.
Show resolved Hide resolved

liamhuber marked this conversation as resolved.
Show resolved Hide resolved
liamhuber marked this conversation as resolved.
Show resolved Hide resolved

runs:
using: 'composite'
steps:
- name: Check if label is patch, minor, or major
id: check_label
shell: bash -l {0}
run: |
if [[ "${{ github.event.label.name }}" == "patch" ]]; then
echo "::set-output name=label::[patch]"
elif [[ "${{ github.event.label.name }}" == "minor" ]]; then
echo "::set-output name=label::[minor]"
elif [[ "${{ github.event.label.name }}" == "major" ]]; then
echo "::set-output name=label::[major]"
else
echo "::set-output name=label::"
fi
liamhuber marked this conversation as resolved.
Show resolved Hide resolved

- name: Update Title on Label Added
if: github.event.action == 'labeled' && steps.check_label.outputs.label != ''
shell: bash -l {0}
run: |
TITLE="${{ github.event.pull_request.title || github.event.issue.title }}"
NEW_TITLE="${{ steps.check_label.outputs.label }} ${TITLE}"
if [[ $TITLE != ${NEW_TITLE} ]]; then
curl -s -X PATCH \
-H "Authorization: Bearer ${{ github.token }}" \
liamhuber marked this conversation as resolved.
Show resolved Hide resolved
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number || github.event.pull_request.number }} \
-d '{"title":"'"$NEW_TITLE"'"}'
fi

- name: Update Title on Label Removed
if: github.event.action == 'unlabeled' && steps.check_label.outputs.label != ''
shell: bash -l {0}
run: |
TITLE="${{ github.event.pull_request.title || github.event.issue.title }}"
LABEL_TO_REMOVE="${{ steps.check_label.outputs.label }}"
NEW_TITLE=$(echo "$TITLE" | perl -pe "s/\Q$LABEL_TO_REMOVE\E//")
NEW_TITLE=$(echo "$NEW_TITLE" | sed 's/ / /g' | sed 's/^ *//;s/ *$//') # Remove extra spaces
if [[ $TITLE != ${NEW_TITLE} ]]; then
curl -s -X PATCH \
-H "Authorization: Bearer ${{ github.token }}" \
liamhuber marked this conversation as resolved.
Show resolved Hide resolved
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number || github.event.pull_request.number }} \
-d '{"title":"'"$NEW_TITLE"'"}'
fi