|
| 1 | +# Copyright (c) 2020 Intel Corporation |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | + |
| 6 | +name: Move issues to "In progress" in backlog project when referenced by a PR |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request_target: |
| 10 | + types: |
| 11 | + - opened |
| 12 | + - reopened |
| 13 | + |
| 14 | +jobs: |
| 15 | + move-linked-issues-to-in-progress: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Install hub |
| 19 | + run: | |
| 20 | + HUB_ARCH="amd64" |
| 21 | + HUB_VER=$(curl -sL "https://api.github.com/repos/github/hub/releases/latest" |\ |
| 22 | + jq -r .tag_name | sed 's/^v//') |
| 23 | + curl -sL \ |
| 24 | + "https://github.com/github/hub/releases/download/v${HUB_VER}/hub-linux-${HUB_ARCH}-${HUB_VER}.tgz" |\ |
| 25 | + tar xz --strip-components=2 --wildcards '*/bin/hub' && \ |
| 26 | + sudo install hub /usr/local/bin |
| 27 | +
|
| 28 | + - name: Install hub extension script |
| 29 | + run: | |
| 30 | + # Clone into a temporary directory to avoid overwriting |
| 31 | + # any existing github directory. |
| 32 | + pushd $(mktemp -d) &>/dev/null |
| 33 | + git clone --single-branch --depth 1 "https://github.com/kata-containers/.github" && cd .github/scripts |
| 34 | + sudo install hub-util.sh /usr/local/bin |
| 35 | + popd &>/dev/null |
| 36 | +
|
| 37 | + - name: Checkout code to allow hub to communicate with the project |
| 38 | + uses: actions/checkout@v2 |
| 39 | + |
| 40 | + - name: Move issue to "In progress" |
| 41 | + env: |
| 42 | + GITHUB_TOKEN: ${{ secrets.KATA_GITHUB_ACTIONS_TOKEN }} |
| 43 | + run: | |
| 44 | + pr=${{ github.event.pull_request.number }} |
| 45 | + linked_issue_urls=$(hub-util.sh list-issue-linked-prs |\ |
| 46 | + grep -v "^\#" |\ |
| 47 | + grep "/pull/${pr};" |\ |
| 48 | + cut -d';' -f2 || true) |
| 49 | +
|
| 50 | + # PR doesn't have any linked issues |
| 51 | + # (it should, but maybe a new user forgot to add a "Fixes #" commit). |
| 52 | + [ -z "$linked_issue_urls" ] \ |
| 53 | + && echo "::error::No linked issues for PR $pr" \ |
| 54 | + && exit 1 |
| 55 | +
|
| 56 | + project_name="Issue backlog" |
| 57 | + project_type="org" |
| 58 | + project_column="In progress" |
| 59 | +
|
| 60 | + for issue_url in $linked_issue_urls |
| 61 | + do |
| 62 | + issue=$(echo "$issue_url"| awk -F\/ '{print $NF}' || true) |
| 63 | +
|
| 64 | + [ -z "$issue" ] \ |
| 65 | + && echo "::error::Cannot determine issue number from $issue_url for PR $pr" \ |
| 66 | + && exit 1 |
| 67 | +
|
| 68 | + # Move the issue to the correct column on the project board |
| 69 | + hub-util.sh \ |
| 70 | + move-issue \ |
| 71 | + "$issue" \ |
| 72 | + "$project_name" \ |
| 73 | + "$project_type" \ |
| 74 | + "$project_column" |
| 75 | + done |
0 commit comments