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

Commit 846b614

Browse files
committed
Merge branch 'rafw87-target_url_path' into develop
#10
2 parents 087c11e + 74f1d97 commit 846b614

File tree

3 files changed

+184
-5
lines changed

3 files changed

+184
-5
lines changed

bin/out

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ eval $( jq -r '{
1010
"params_state": .params.state,
1111
"params_description": ( .params.description // "" ),
1212
"params_description_path": ( .params.description_path // "" ),
13-
"params_target_url": ( .params.target_url // "$ATC_EXTERNAL_URL/builds/$BUILD_ID" )
13+
"params_target_url": ( .params.target_url // ""),
14+
"params_target_url_path": ( .params.target_url_path // "" )
1415
} | to_entries[] | .key + "=" + @sh "\(.value)"' < /tmp/stdin )
1516

1617

@@ -59,10 +60,12 @@ fi
5960
# target_url
6061
#
6162

62-
target_url=""
63+
target_url='$ATC_EXTERNAL_URL/builds/$BUILD_ID'
6364

64-
if [ -n "$params_target_url" ] ; then
65-
target_url=$( echo "$params_target_url" | buildtpl )
65+
if [[ -n "$params_target_url" ]] ; then
66+
target_url="$params_target_url"
67+
elif [[ -n "$params_target_url_path" ]] ; then
68+
target_url="$( cat "$params_target_url_path" )"
6669
fi
6770

6871

@@ -72,7 +75,7 @@ fi
7275

7376
jq -c -n \
7477
--arg state "$params_state" \
75-
--arg target_url "$target_url" \
78+
--arg target_url "$( echo "$target_url" | buildtpl )" \
7679
--arg description "$( cat $description_path )" \
7780
--arg context "$source_context" \
7881
'{

test/out/default-target-url.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
DIR=$( dirname "$0" )/../..
6+
7+
echo 'a1b2c3d4e5' > $TMPDIR/commit
8+
9+
cat <<EOF | nc -l -s 127.0.0.1 -p 9192 > $TMPDIR/http.req-$$ &
10+
HTTP/1.0 200 OK
11+
12+
{
13+
"created_at": "2012-07-20T01:19:13Z",
14+
"updated_at": "2012-07-20T02:19:13Z",
15+
"state": "success",
16+
"target_url": "https://ci.example.com/1000/output",
17+
"description": "Build has completed successfully",
18+
"id": 1,
19+
"url": "https://api.github.com/repos/octocat/Hello-World/statuses/1",
20+
"context": "continuous-integration/jenkins",
21+
"creator": {
22+
"login": "octocat",
23+
"id": 1,
24+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
25+
"gravatar_id": "",
26+
"url": "https://api.github.com/users/octocat",
27+
"html_url": "https://github.com/octocat",
28+
"followers_url": "https://api.github.com/users/octocat/followers",
29+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
30+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
31+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
32+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
33+
"organizations_url": "https://api.github.com/users/octocat/orgs",
34+
"repos_url": "https://api.github.com/users/octocat/repos",
35+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
36+
"received_events_url": "https://api.github.com/users/octocat/received_events",
37+
"type": "User",
38+
"site_admin": false
39+
}
40+
}
41+
EOF
42+
43+
ATC_EXTERNAL_URL=http://localhost BUILD_ID=123 $DIR/bin/out > $TMPDIR/resource-$$ <<EOF
44+
{
45+
"params": {
46+
"description": "test-description",
47+
"commit": "$TMPDIR/commit",
48+
"state": "success"
49+
},
50+
"source": {
51+
"access_token": "test-token",
52+
"context": "test-context",
53+
"endpoint": "http://127.0.0.1:9192",
54+
"repository": "dpb587/test-repo"
55+
}
56+
}
57+
EOF
58+
59+
if ! grep -q '^POST /repos/dpb587/test-repo/statuses/a1b2c3d4e5 ' $TMPDIR/http.req-$$ ; then
60+
echo "FAILURE: Invalid HTTP method or URI"
61+
cat $TMPDIR/http.req-$$
62+
exit 1
63+
fi
64+
65+
if ! grep -q '^{"context":"test-context","description":"test-description","state":"success","target_url":"http://localhost/builds/123"}$' $TMPDIR/http.req-$$ ; then
66+
echo "FAILURE: Unexpected request body"
67+
cat $TMPDIR/http.req-$$
68+
exit 1
69+
fi
70+
71+
if ! grep -q '"version":{"commit":"a1b2c3d4e5","status":"1"}' $TMPDIR/resource-$$ ; then
72+
echo "FAILURE: Unexpected version output"
73+
cat $TMPDIR/resource-$$
74+
exit 1
75+
fi
76+
77+
if ! grep -q '{"name":"created_at","value":"2012-07-20T01:19:13Z"}' $TMPDIR/resource-$$ ; then
78+
echo "FAILURE: Unexpected created_at output"
79+
cat $TMPDIR/resource-$$
80+
exit 1
81+
fi
82+
83+
if ! grep -q '{"name":"created_by","value":"octocat"}' $TMPDIR/resource-$$ ; then
84+
echo "FAILURE: Unexpected creator output"
85+
cat $TMPDIR/resource-$$
86+
exit 1
87+
fi

test/out/target-url-path.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
DIR=$( dirname "$0" )/../..
6+
7+
echo 'a1b2c3d4e5' > $TMPDIR/commit
8+
echo 'https://ci.example.com/$BUILD_ID/output-path' > $TMPDIR/target_url
9+
10+
cat <<EOF | nc -l -s 127.0.0.1 -p 9192 > $TMPDIR/http.req-$$ &
11+
HTTP/1.0 200 OK
12+
13+
{
14+
"created_at": "2012-07-20T01:19:13Z",
15+
"updated_at": "2012-07-20T02:19:13Z",
16+
"state": "success",
17+
"target_url": "https://ci.example.com/1000/output",
18+
"description": "Build has completed successfully",
19+
"id": 1,
20+
"url": "https://api.github.com/repos/octocat/Hello-World/statuses/1",
21+
"context": "continuous-integration/jenkins",
22+
"creator": {
23+
"login": "octocat",
24+
"id": 1,
25+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
26+
"gravatar_id": "",
27+
"url": "https://api.github.com/users/octocat",
28+
"html_url": "https://github.com/octocat",
29+
"followers_url": "https://api.github.com/users/octocat/followers",
30+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
31+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
32+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
33+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
34+
"organizations_url": "https://api.github.com/users/octocat/orgs",
35+
"repos_url": "https://api.github.com/users/octocat/repos",
36+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
37+
"received_events_url": "https://api.github.com/users/octocat/received_events",
38+
"type": "User",
39+
"site_admin": false
40+
}
41+
}
42+
EOF
43+
44+
BUILD_ID=123 $DIR/bin/out > $TMPDIR/resource-$$ <<EOF
45+
{
46+
"params": {
47+
"description": "test-description",
48+
"commit": "$TMPDIR/commit",
49+
"state": "success",
50+
"target_url_path": "$TMPDIR/target_url"
51+
},
52+
"source": {
53+
"access_token": "test-token",
54+
"context": "test-context",
55+
"endpoint": "http://127.0.0.1:9192",
56+
"repository": "dpb587/test-repo"
57+
}
58+
}
59+
EOF
60+
61+
if ! grep -q '^POST /repos/dpb587/test-repo/statuses/a1b2c3d4e5 ' $TMPDIR/http.req-$$ ; then
62+
echo "FAILURE: Invalid HTTP method or URI"
63+
cat $TMPDIR/http.req-$$
64+
exit 1
65+
fi
66+
67+
if ! grep -q '^{"context":"test-context","description":"test-description","state":"success","target_url":"https://ci.example.com/123/output-path"}$' $TMPDIR/http.req-$$ ; then
68+
echo "FAILURE: Unexpected request body"
69+
cat $TMPDIR/http.req-$$
70+
exit 1
71+
fi
72+
73+
if ! grep -q '"version":{"commit":"a1b2c3d4e5","status":"1"}' $TMPDIR/resource-$$ ; then
74+
echo "FAILURE: Unexpected version output"
75+
cat $TMPDIR/resource-$$
76+
exit 1
77+
fi
78+
79+
if ! grep -q '{"name":"created_at","value":"2012-07-20T01:19:13Z"}' $TMPDIR/resource-$$ ; then
80+
echo "FAILURE: Unexpected created_at output"
81+
cat $TMPDIR/resource-$$
82+
exit 1
83+
fi
84+
85+
if ! grep -q '{"name":"created_by","value":"octocat"}' $TMPDIR/resource-$$ ; then
86+
echo "FAILURE: Unexpected creator output"
87+
cat $TMPDIR/resource-$$
88+
exit 1
89+
fi

0 commit comments

Comments
 (0)