Skip to content

Commit

Permalink
Initial import of script
Browse files Browse the repository at this point in the history
  • Loading branch information
wesley-dean-gsa committed Aug 22, 2024
1 parent 7b1b87b commit 87bd87d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bin/has_newer_commits.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -euo pipefail

fetch_data() {

url="${1?Error: no URL provided}"

curl \
-s \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer ${PAT}" \
"$url"

}

compare_dates() {
{
fetch_data "$(build_url "$a")"
fetch_data "$(build_url "$b")"
} | jq \
--raw-output \
--slurp \
'if .[0].commit.commit.author.date < .[1].commit.commit.author.date then true else false end'
}

build_url() {
item="${1?Error: no owner/repo@branch passed}"

repo="${item%%@*}"
branch="${item##*@}"

if [ "$branch" == "$repo" ] ; then
repo="$item"
branch="main"
fi

echo "https://api.github.com/repos/${repo}/branches/${branch}"
}

a="${1?Error: two owner/repo@branch values must be provided (0 were)}"
b="${2?Error: two owner/repo@branch values must be provided (1 was)}"

if [ "$(compare_dates "$a" "$b")" == "true" ] ; then
exit 0
else
exit 1
fi

0 comments on commit 87bd87d

Please sign in to comment.