Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 691595a

Browse files
committed
Use commit sha as part of the resource version
1 parent 1975be4 commit 691595a

File tree

8 files changed

+22
-15
lines changed

8 files changed

+22
-15
lines changed

bin/check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ load_source
88
curlgh "$source_endpoint/repos/$source_repository/commits/$source_branch/status" \
99
| jq -c \
1010
--arg context "$source_context" \
11-
'.statuses | map(select( $context == .context )) | map({ "ref": ( .id | tostring ) })' \
11+
'.sha as $commit | .statuses | map(select( $context == .context )) | map({ "commit": $commit, "status": ( .id | tostring ) })' \
1212
>&3

bin/in

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ in_dir="$1"
77
load_source
88

99
eval $( jq -r '{
10-
"version_ref": .version.ref
10+
"version_commit": .version.commit,
11+
"version_status": .version.status
1112
} | to_entries[] | .key + "=" + @sh "\(.value)"' < /tmp/stdin )
1213

1314

1415
#
1516
# lookup
1617
#
1718

18-
curlgh "$source_endpoint/repos/$source_repository/commits/$source_branch/status" \
19+
curlgh "$source_endpoint/repos/$source_repository/commits/$version_commit/status" \
1920
| jq -c \
20-
--arg ref "$version_ref" \
21+
--arg status "$version_status" \
2122
'{
2223
"sha": .sha,
23-
"status": ( .statuses | map(select( $ref == ( .id | tostring ) )) | .[0] )
24+
"status": ( .statuses | map(select( $status == ( .id | tostring ) )) | .[0] )
2425
}' \
2526
> /tmp/status
2627

@@ -44,10 +45,12 @@ jq -j -r '.status.target_url // ""' < /tmp/status > "$in_dir/target_url"
4445
jq -j -r '.status.updated_at' < /tmp/status > "$in_dir/updated_at"
4546

4647
jq -c \
47-
--arg ref "$version_ref" \
48+
--arg commit "$version_commit" \
49+
--arg status "$version_status" \
4850
'{
4951
"version": {
50-
"ref": ( $ref | tostring )
52+
"commit": ( $commit | tostring ),
53+
"status": ( $status | tostring )
5154
},
5255
"metadata": [
5356
{

bin/out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ done
115115
#
116116

117117
jq -c \
118+
--arg commit "$commit" \
118119
'{
119120
"version": {
120-
"ref": ( .id | tostring )
121+
"commit": $commit,
122+
"status": ( .id | tostring )
121123
},
122124
"metadata": [
123125
{

test/check/simple.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if ! grep -q '^GET /repos/dpb587/test-repo/commits/pr-test/status ' $TMPDIR/http
5454
exit 1
5555
fi
5656

57-
if ! [[ '[{"ref":"2"}]' == "$( cat $TMPDIR/resource-$$ )" ]] ; then
57+
if ! [[ '[{"commit":"6dcb09b5b57875f334f61aebed695e2e4193db5e","status":"2"}]' == "$( cat $TMPDIR/resource-$$ )" ]] ; then
5858
echo "FAILURE: Unexpected version output"
5959
cat $TMPDIR/resource-$$
6060
exit 1

test/in/missing-status.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ set +e
2222
$DIR/bin/in "$in_dir" > $TMPDIR/resource-$$ 2>&1 <<EOF
2323
{
2424
"version": {
25-
"ref": "2"
25+
"commit": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
26+
"status": "2"
2627
},
2728
"source": {
2829
"access_token": "test-token",

test/in/simple.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ mkdir $in_dir
4646
$DIR/bin/in "$in_dir" > $TMPDIR/resource-$$ <<EOF
4747
{
4848
"version": {
49-
"ref": "2"
49+
"commit": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
50+
"status": "2"
5051
},
5152
"source": {
5253
"access_token": "test-token",
@@ -57,7 +58,7 @@ $DIR/bin/in "$in_dir" > $TMPDIR/resource-$$ <<EOF
5758
}
5859
EOF
5960

60-
if ! grep -q '^GET /repos/dpb587/test-repo/commits/master/status ' $TMPDIR/http.req-$$ ; then
61+
if ! grep -q '^GET /repos/dpb587/test-repo/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/status ' $TMPDIR/http.req-$$ ; then
6162
echo "FAILURE: Invalid HTTP method or URI"
6263
cat $TMPDIR/http.req-$$
6364
exit 1
@@ -93,7 +94,7 @@ if ! [[ "2012-08-20T01:19:13Z" == "$( cat $in_dir/updated_at )" ]] ; then
9394
exit 1
9495
fi
9596

96-
if ! grep -q '"version":{"ref":"2"}' $TMPDIR/resource-$$ ; then
97+
if ! grep -q '"version":{"commit":"6dcb09b5b57875f334f61aebed695e2e4193db5e","status":"2"}' $TMPDIR/resource-$$ ; then
9798
echo "FAILURE: Unexpected version output"
9899
cat $TMPDIR/resource-$$
99100
exit 1

test/out/simple.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ if ! grep -q '^{"context":"test-context","description":"test-description","state
6969
exit 1
7070
fi
7171

72-
if ! grep -q '"version":{"ref":"1"}' $TMPDIR/resource-$$ ; then
72+
if ! grep -q '"version":{"commit":"a1b2c3d4e5","status":"1"}' $TMPDIR/resource-$$ ; then
7373
echo "FAILURE: Unexpected version output"
7474
cat $TMPDIR/resource-$$
7575
exit 1

test/out/wait-for-status.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if ! grep -q '^{"context":"test-context","description":"test-description","state
144144
exit 1
145145
fi
146146

147-
if ! grep -q '"version":{"ref":"1"}' $TMPDIR/resource-$$ ; then
147+
if ! grep -q '"version":{"commit":"a1b2c3d4e5","status":"1"}' $TMPDIR/resource-$$ ; then
148148
echo "FAILURE: Unexpected version output"
149149
cat $TMPDIR/resource-$$
150150
exit 1

0 commit comments

Comments
 (0)