Skip to content

Commit

Permalink
Support linking PRs with tickets through commit messages [MDB-24383]
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Burmak committed Aug 15, 2023
1 parent a1c70c6 commit ec14efc
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/link_startrek.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
name: startrek link
name: Link with Startrek

on:
pull_request: { branches: [main] }

env:
ISSUE_PATTERN: '[A-Z]+-[0-9]+'

jobs:
link_with_startrek:
link:
runs-on: ubuntu-latest
steps:
- name: parse_branch_name
id: parse_branch_name
- name: Parse issue ID
run: |
if [[ ${{ github.head_ref }} =~ ^([A-Za-z]+\-[0-9]+).*$ ]]; then
echo issue_number="${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
LAST_COMMIT_MESSAGE="$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "${{ github.event.pull_request.commits_url }}" | jq -r .[-1].commit.message)"
if [[ "$LAST_COMMIT_MESSAGE" =~ \[($ISSUE_PATTERN)\] || "${{ github.head_ref }}" =~ ^($ISSUE_PATTERN) ]]; then
echo ISSUE_NUMBER="${BASH_REMATCH[1]}" >> "${GITHUB_ENV}"
fi
- name: link_issue
if: steps.parse_branch_name.outputs.issue_number
- name: Link issue
if: env.ISSUE_NUMBER
uses: fjogeleit/http-request-action@v1
with:
url: 'https://st-api.yandex-team.ru/v2/issues/${{ steps.parse_branch_name.outputs.issue_number }}'
url: 'https://st-api.yandex-team.ru/v2/issues/${{ env.ISSUE_NUMBER }}'
method: 'LINK'
customHeaders: >
{
"Link": "<${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.number }}>; rel=\"relates\"",
"Authorization": "OAuth ${{ secrets.OAUTH_STARTREK_TOKEN }}"
}
ignoreStatusCodes: '409'
ignoreStatusCodes: 409

0 comments on commit ec14efc

Please sign in to comment.