Skip to content

Commit

Permalink
Harden notary script
Browse files Browse the repository at this point in the history
- Set and use `SCRIPTDIR` to be agnostic of the current working
  directory (i.e.: being able to execute it outside of `parsec-cloud`
  repo)
- Rework `Debug tool version` block to oneline tools' version instead of
  relying on debug output (`set -x`).

  This allow to run the script with `-x` without it being disable by the
  `set +x`.
- Allow to provide additional args to `Github-CLI` via the optional var
  `GH_ADDITIONAL_ARGS` (useful to set `--repo=<Owner>/<Repo>`)

Co-authored-by: Marcos Medrano <786907+mmmarcos@users.noreply.github.com>
  • Loading branch information
FirelightFlagboy and mmmarcos committed Dec 15, 2023
1 parent 4e309b4 commit 572c036
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/scripts/notary/lib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!bash

QUERY_FOLDER=.github/scripts/notary/graphql
#!/usr/bin/env bash
SCRIPTDIR=${SCRIPTDIR:="$(dirname $(realpath -s "$0"))"}
QUERY_FOLDER=$SCRIPTDIR/graphql

# List project fields like `status`, `tag`, `labels` and other
function list_project_fields() {
Expand Down
22 changes: 11 additions & 11 deletions .github/scripts/notary/script.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!bash
source .github/scripts/notary/lib.sh
#!/usr/bin/env bash
SCRIPTDIR=${SCRIPTDIR:="$(dirname $(realpath -s "$0"))"}
source "$SCRIPTDIR"/lib.sh

if [ $# -ne 2 ]; then
echo "usage: $0 <ORGA> <PROJECT_NUMBER>" 1>&2
Expand All @@ -8,14 +9,13 @@ fi

PROJECT_ORGA=${1}
PROJECT_NUMBER=${2}
GH="gh ${GH_ADDITIONAL_ARGS:=""}"

set -o pipefail
echo "Debug tool version"
set -x
gh --version
jq --version
base64 --version
set +x
echo "Debug tools version:"
echo "- gh version: $(gh --version | head -n 1)"
echo "- jq version: $(jq --version)"
echo "- base64 version: $(base64 --version | head -n 1)"

TMP_DIR=$(mktemp --tmpdir --directory "notary.XXXX")
echo "temporary folder is $TMP_DIR"
Expand All @@ -25,14 +25,14 @@ echo "Looking for issues that are assigned to the wrong project."
touch $TMP_DIR/issues_wrong_project.json

# Search for Issue that aren't linked to the board already
gh issue list \
$GH issue list \
--json id,title,number \
--search "-project:\"$PROJECT_ORGA/$PROJECT_NUMBER\"" \
--jq '.[] += {"type": "issue"} | .[]' \
| tee -a $TMP_DIR/issues_wrong_project.json

# Search for PRs that aren't linked to the board and linked to an issue
gh pr list \
$GH pr list \
--json id,title,number \
--search "-project:\"$PROJECT_ORGA/$PROJECT_NUMBER\" -linked:issue" \
--jq '.[] += {"type": "pr"} | .[]' \
Expand All @@ -58,8 +58,8 @@ for raw_row in $(<$TMP_DIR/issues_wrong_project.json.b64); do

echo -n "Adding $TYPE \"$TITLE\" to project $PROJECT_TITLE > "
add_item_to_project $PROJECT_ID $ID
echo
RC=$?
echo
if [ $RC -ne 0 ]; then
echo "Failed to add $TYPE \"$TITLE\" to project $PROJECT_TITLE" >&2
exit $RC
Expand Down

0 comments on commit 572c036

Please sign in to comment.