Skip to content

Commit

Permalink
Merge pull request #2 from kentos/feat-skip-drafts
Browse files Browse the repository at this point in the history
feat: add option to skip drafts
  • Loading branch information
crazymanish authored Feb 27, 2023
2 parents cd9fe14 + 1ef7247 commit e258aeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ inputs:
SKIP_LABELS:
description: 'The comma separated labels string. If an open pull-request has one of those label then this action will skip adding the attention label.'
default: 'work-in-progress,wip'
SKIP_DRAFTS:
description: 'Wheter to skip draft PRs or not. Defaults to include them'
default: true
runs:
using: 'docker'
image: 'Dockerfile'
15 changes: 14 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ if [[ -z "$AFTER_DAYS" ]]; then
AFTER_DAYS=3
fi

if [[ -z "$SKIP_DRAFTS" ]]; then
echo "Setting the default SKIP_DRAFTS variable value."
SKIP_DRAFTS=false
fi

URI="https://api.github.com"
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
Expand All @@ -33,7 +38,7 @@ OPEN_PULL_REQUESTS=$(
"$URI/repos/$GITHUB_REPOSITORY/issues?state=open"
)

PULL_REQUESTS=$(echo "$OPEN_PULL_REQUESTS" | jq --raw-output '.[] | {number: .number, created_at: .created_at, labels: .labels} | @base64')
PULL_REQUESTS=$(echo "$OPEN_PULL_REQUESTS" | jq --raw-output '.[] | {number: .number, created_at: .created_at, labels: .labels, draft: .draft} | @base64')

for PULL_REQUEST in $PULL_REQUESTS; do
PULL_REQUEST_INFO="$(echo "$PULL_REQUEST" | base64 -d)"
Expand Down Expand Up @@ -67,6 +72,14 @@ for PULL_REQUEST in $PULL_REQUESTS; do
continue
fi

if [[ $SKIP_DRAFTS != "false" ]]; then
IS_A_DRAFT=$(echo "$PULL_REQUEST_INFO" | jq --raw-output '.draft')
if [[ $IS_A_DRAFT == "true" ]]; then
echo "Ignoring, this pull request because it's a DRAFT"
continue
fi
fi

CREATED_AT=$(echo "$PULL_REQUEST_INFO" | jq --raw-output '.created_at')
CREATED_AT_EPOCH=$(date -d $CREATED_AT +%s)
CURRENT_EPOCH=$(date +%s)
Expand Down

0 comments on commit e258aeb

Please sign in to comment.