Skip to content

Commit

Permalink
cache user json
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed Sep 24, 2023
1 parent 7e0248f commit 465b3a8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions gh-act
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" &>/dev/null && pwd -P)

GH_ACT_VERSION=0.5
TEMPFILE_DIR=

msg() {
echo >&2 -e "${1-}"
Expand Down Expand Up @@ -198,7 +199,7 @@ function is_valid_user {
return $?
}

function user_json {
function user_json_ {
# shellcheck disable=SC2016,SC2086
USER_JSON_TEMPLATE='{
"avatar_url": "{{.avatar_url}}",
Expand Down Expand Up @@ -229,6 +230,15 @@ function user_json {
fi
}

function user_json {

if [ -f "${TEMPFILE_DIR}/users/$1.json" ]; then
cat "${TEMPFILE_DIR}/users/$1.json"
fi

user_json_ "$1" | tee "${TEMPFILE_DIR}/users/$1.json"
}

function issue_json {
ISSUE_NUMBER=$1
parts_json issue
Expand Down Expand Up @@ -428,7 +438,7 @@ function pull_request_event_envs() {

# shellcheck disable=SC2086
BEFORE=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].oid | tail -2 | head -1)
# shellcheck disable=SC2086
# shellcheck disable=SC2016
read -r HEAD HEAD_USER <<< $(gh pr view ${PULL_REQUEST_SPEC} --json commits \
--template '{{- $last := 0}}
{{- range $index, $element := .commits}}{{$last = $index}}{{end}}
Expand Down Expand Up @@ -1167,6 +1177,7 @@ function create_event_json() {
if [ -f "${SCRIPT_DIR}/templates/${EVENT_NAME}.json" ]; then

# common
# shellcheck disable=SC2046
read -r OWNER REPO \
<<< $(gh repo view --json owner,name --template '{{ .owner.login }} {{ .name }}')

Expand Down Expand Up @@ -1270,10 +1281,10 @@ function act_post_action() {
true
}

TEMPFILE_DIR=
function tempdir() {
if [ -z "${TEMPFILE_DIR}" ] || [ ! -d "${TEMPFILE_DIR}" ]; then
TEMPFILE_DIR=$(mktemp -d gh-act.XXXXXX)
mkdir "${TEMPFILE_DIR}/users"
trap 'rm -rf "${TEMPFILE_DIR}"' EXIT
fi
}
Expand Down

0 comments on commit 465b3a8

Please sign in to comment.