Skip to content

Commit

Permalink
Merge pull request #1 from homeport/add/label
Browse files Browse the repository at this point in the history
Add `labels` option
  • Loading branch information
HeavyWombat authored Sep 20, 2023
2 parents 68e640e + a96ea5e commit c12b94e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ _Note:_ Currently, only checking and using it for `get` steps is supported.

* `repository`: _Required._ The GitHub repository to work with, for example `homeport/github-issue-resource`.

* `labels`: _Optional_ List of labels to use in the issue list filter.

### Example

Since it is a custom resource type, it has to be configured once in the pipeline configuration.
Expand All @@ -37,6 +39,7 @@ resources:
hostname: github.com
token: ((github-access-token))
repository: homeport/github-issue-resource
labels: ["foobar"]

jobs:
- name: some-job
Expand Down
27 changes: 18 additions & 9 deletions scripts/check
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,39 @@
set -euo pipefail

CONFIG="$(cat)"
echo >&2 -e "\\033[1mConfig\\033[0m: $(jq -c -C '.source.token="***"' <<<"${CONFIG}")"
echo >&2 -e "\\033[1mConfig\\033[0m: $(jq -C '.source.token="***"' <<<"$CONFIG")"

HOSTNAME="$(jq --raw-output '.source.hostname // ""' <<<"${CONFIG}")"
HOSTNAME="$(jq --raw-output '.source.hostname // ""' <<<"$CONFIG")"
if [[ -z $HOSTNAME ]]; then
echo >&2 "No hostname specified: Use .source.hostname to define the hostname to be used"
exit 1
fi

TOKEN="$(jq --raw-output '.source.token // ""' <<<"${CONFIG}")"
TOKEN="$(jq --raw-output '.source.token // ""' <<<"$CONFIG")"
if [[ -z $TOKEN ]]; then
echo >&2 "No token specified: Use .source.token to define the token to be used"
exit 1
fi

REPOSITORY="$(jq --raw-output '.source.repository // ""' <<<"${CONFIG}")"
REPOSITORY="$(jq --raw-output '.source.repository // ""' <<<"$CONFIG")"
if [[ -z $REPOSITORY ]]; then
echo >&2 "No repository specified: Use .source.repository to define the repository to be used"
exit 1
fi

# Setup default list arguments
LIST_ARGS=("--limit" "1024" "--json" "number")

# Add label flags if required based on source
while IFS=$'\t' read -r LABEL; do
if [[ -n $LABEL ]]; then
LIST_ARGS+=(
"--label" "$LABEL"
)
fi
done <<<"$(jq --raw-output '(.source.labels // [])[] | [.] | @tsv' <<<"$CONFIG")"

export GH_HOST="$HOSTNAME"
gh auth login --hostname "$HOSTNAME" --with-token <<<"${TOKEN}" >&2
gh --repo "$HOSTNAME/$REPOSITORY" \
issue list \
--limit 1024 \
--json number |
#gh auth login --hostname "$HOSTNAME" --with-token <<<"${TOKEN}" >&2
gh --repo "$HOSTNAME/$REPOSITORY" issue list "${LIST_ARGS[@]}" |
jq '[ sort_by(.number)[] | { "issue": .number | tostring } ]'

0 comments on commit c12b94e

Please sign in to comment.