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

Add position input #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<card_id>'`.

## Example usage

Examples of action:
Expand Down Expand Up @@ -62,14 +66,15 @@ 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/[email protected]
if: |
contains(github.event.issue.labels.*.name, 'bug') ||
contains(github.event.pull_request.labels.*.name, 'bug')
with:
project: 'https://github.com/srggrs/assign-one-project-github-action/projects/3'
column_name: 'Labeled'
position: 'bottom'
```

#### __Notes__
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:<card_id>".'
required: false


runs:
using: 'docker'
Expand Down
21 changes: 16 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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