From b7166acb390cf69970a999cb3aeceace2f74f7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gaul?= Date: Tue, 5 Oct 2021 11:04:39 +0200 Subject: [PATCH] add position input --- README.md | 7 ++++++- action.yml | 4 ++++ entrypoint.sh | 21 ++++++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1b2fa18..45c12bf 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ I would like to thank @SunRunAway for adding the labelling functionality and cus The column name of the project, defaults to `'To do'` for issues and `'In progress'` for pull requests. +### `position` + +Position for new card. Defaults to `'top'`. Valid values are `'top'`, `'bottom'` and `'after:'`. + ## Example usage Examples of action: @@ -62,7 +66,7 @@ jobs: with: project: 'https://github.com/srggrs/assign-one-project-github-action/projects/2' - - name: Assign issues and pull requests with `bug` label to project 3 + - name: Assign issues and pull requests with `bug` label to project 3 at the bottom uses: srggrs/assign-one-project-github-action@1.2.1 if: | contains(github.event.issue.labels.*.name, 'bug') || @@ -70,6 +74,7 @@ jobs: with: project: 'https://github.com/srggrs/assign-one-project-github-action/projects/3' column_name: 'Labeled' + position: 'bottom' ``` #### __Notes__ diff --git a/action.yml b/action.yml index 40f7a12..8cc5b71 100644 --- a/action.yml +++ b/action.yml @@ -9,6 +9,10 @@ inputs: column_name: description: 'The column name of the project, defaults to "To do" for issues and "In progress" for pull requests.' required: false + position: + description: 'Position for new card. Defaults to "top". Valid values are "top", "bottom", "after:".' + required: false + runs: using: 'docker' diff --git a/entrypoint.sh b/entrypoint.sh index 05b81c7..4778cac 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -50,7 +50,7 @@ find_project_id() { _ENDPOINT="https://api.github.com/repos/$GITHUB_REPOSITORY/projects?per_page=100" ;; esac - + _NEXT_URL="$_ENDPOINT" while : ; do @@ -129,22 +129,33 @@ case "$GITHUB_EVENT_NAME" in ISSUE_ID=$(jq -r '.issue.id' < "$GITHUB_EVENT_PATH") # Add this issue to the project column - curl -s -X POST -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \ + _CARD=$(curl -s -X POST -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \ -H 'Accept: application/vnd.github.inertia-preview+json' \ -d "{\"content_type\": \"Issue\", \"content_id\": $ISSUE_ID}" \ - "https://api.github.com/projects/columns/$INITIAL_COLUMN_ID/cards" + "https://api.github.com/projects/columns/$INITIAL_COLUMN_ID/cards") ;; pull_request|pull_request_target) PULL_REQUEST_ID=$(jq -r '.pull_request.id' < "$GITHUB_EVENT_PATH") # Add this pull_request to the project column - curl -s -X POST -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \ + _CARD=$(curl -s -X POST -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \ -H 'Accept: application/vnd.github.inertia-preview+json' \ -d "{\"content_type\": \"PullRequest\", \"content_id\": $PULL_REQUEST_ID}" \ - "https://api.github.com/projects/columns/$INITIAL_COLUMN_ID/cards" + "https://api.github.com/projects/columns/$INITIAL_COLUMN_ID/cards") ;; *) echo "Nothing to be done on this action: '$GITHUB_EVENT_NAME'" >&2 exit 1 ;; esac + +CARD_ID=$(echo "$_CARD" | jq -r '.id') +echo "Card $CARD_ID created." + +INITIAL_POSITION="$INPUT_POSITION" +if [ -n "$INITIAL_POSITION" ] && [ "$INITIAL_POSITION" != "top" ]; then + curl -s -X POST -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \ + -H 'Accept: application/vnd.github.inertia-preview+json' \ + -d "{\"position\": \"$INITIAL_POSITION\"}" \ + "https://api.github.com/projects/columns/cards/$CARD_ID/moves" +fi