2
2
# vim: set ft=sh
3
3
4
4
set -e
5
+ set -o pipefail
5
6
6
7
exec 3>&1 # make stdout available as fd 3 for the result
7
8
exec 1>&2 # redirect all output to stderr for logging
@@ -48,45 +49,27 @@ if [ -z "$uri" ]; then
48
49
exit 1
49
50
fi
50
51
51
- # if option 'rebuild_when_target_changed' is enabled take merge branch since commit will always change for changes on target branch
52
- prq_branch=" from"
53
- if [ " $rebuild_when_target_changed " == " true" ]; then
54
- prq_branch=" merge"
55
- fi
56
-
57
- # collect all pull requests from uri
58
- pull_requests=$( git ls-remote " $uri " | grep -E " /pull\-requests/[0-9]+/${prq_branch} " | cat)
59
-
60
52
versions=" []"
61
- if [ -n " $pull_requests " ]; then
62
- log " Calculating repository specifics"
63
- # determine repository name for calling REST api
64
- repo_name=$( basename " $uri " | sed " s/.git$//" )
65
- repo_project=$( basename $( dirname " $uri " ) )
66
-
67
- # parse uri and retrieve host
68
- uri_parser " $uri "
69
- repo_host=" ${uri_schema} ://${uri_address} "
70
53
71
- repo_host=${repo_host} $( getBasePathOfBitbucket)
54
+ log " Calculating repository specifics"
55
+ # determine repository name for calling REST api
56
+ repo_name=$( basename " $uri " | sed " s/.git$//" )
57
+ repo_project=$( basename $( dirname " $uri " ) )
72
58
73
- versions=" []"
74
- while read pull_request ; do
75
- log " Verifying pull request"
76
- # determine hash and prq number from grep
77
- prq_number=$( echo " $pull_request " | sed -E " s/^.*\/pull-requests\/([0-9]+)\/.*$/\\ 1/" )
78
- prq_hash=$( echo " $pull_request " | awk ' {print $1}' )
59
+ # parse uri and retrieve host
60
+ uri_parser " $uri "
61
+ repo_host=" ${uri_schema} ://${uri_address} "
79
62
80
- # verify target branch of prq
81
- prq=$( bitbucket_pullrequest " $repo_host " " $repo_project " " $repo_name " " $prq_number " " " " $skip_ssl_verification " )
63
+ repo_host=${repo_host} $( getBasePathOfBitbucket)
82
64
83
- if [ " $prq " = " ERROR " ] ; then
84
- continue
85
- fi
65
+ # collect all pull requests from uri and loop on them
66
+ pull_requests= $( bitbucket_pullrequests " $repo_host " " $repo_project " " $repo_name " " " " $skip_ssl_verification " |
67
+ jq -er ' .[] | [.id, .fromRef.latestCommit, .toRef.latestCommit, .toRef.displayId, .createdDate]|@tsv ' )
86
68
87
- log " Pull request #${prq_number} "
69
+ if [ -n " $pull_requests " ]; then
70
+ while IFS=$' \t ' read -r prq_number from_hash to_hash prq_to_branch prq_verify_date; do
71
+ log " Verifying pull request #${prq_number} "
88
72
89
- prq_to_branch=$( echo " $prq " | jq -r ' .toRef.displayId' )
90
73
if [[ " $prq_to_branch " =~ $only_for_branch ]]; then
91
74
92
75
if [ " $only_when_mergeable " == " true" -o " $only_without_conflicts " == " true" ]; then
@@ -102,15 +85,18 @@ if [ -n "$pull_requests" ]; then
102
85
fi
103
86
104
87
# edit timestamp to version to force new build when rebuild_phrase is included in comments
105
- prq_verify_date=$( echo " $prq " | jq -r ' .createdDate' )
106
88
skip_build=false
107
89
comments=$( bitbucket_pullrequest_overview_comments " $repo_host " " $repo_project " " $repo_name " " $prq_number " " " " $skip_ssl_verification " | jq -c ' .[]' )
108
90
if [ -n " $comments " ]; then
109
91
while read -r comment; do
110
92
text=$( echo " $comment " | jq -r ' .text' )
111
93
112
94
# check for progress or finished messages => do not include in versions when available
113
- if bitbucket_pullrequest_comment_commit_match " $text " " $prq_hash " ; then
95
+ hash=" $from_hash "
96
+ if [ " $rebuild_when_target_changed " == " true" ]; then
97
+ hash=" $to_hash "
98
+ fi
99
+ if bitbucket_pullrequest_comment_commit_match " $text " " $hash " ; then
114
100
log " Skipping PRQ #$prq_number since already handled"
115
101
skip_build=true
116
102
break
@@ -127,7 +113,12 @@ if [ -n "$pull_requests" ]; then
127
113
# add prq to versions
128
114
if [ " $skip_build " == " false" ]; then
129
115
pretty_date=$( date_from_epoch_seconds " $(( ($prq_verify_date + 500 ) / 1000 )) " )
130
- versions+=" + [{ id: \" $prq_number \" , hash: \" $prq_hash \" , date: \" $pretty_date \" , change: $prq_verify_date }]"
116
+
117
+ if [ " $rebuild_when_target_changed " == " false" ]; then
118
+ to_hash=" "
119
+ fi
120
+
121
+ versions+=" + [{ id: \" $prq_number \" , from: \" $from_hash \" , to: \" $to_hash \" , date: \" $pretty_date \" , change: $prq_verify_date }]"
131
122
fi
132
123
133
124
fi
0 commit comments