Skip to content

Commit

Permalink
Skip PR if wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Данильсон Дмитрий authored and idr0id committed Dec 27, 2018
1 parent ba8d590 commit 85299c6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions assets/check
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ if [[ "$bitbucket_type" == "server" ]]; then
curl -sS --fail -u ${username}:${password} $uri | jq -r \
'.values
| map({
id: .id | tostring,
id: .id | tostring,
title: .title | tostring,
branch: .fromRef.id | tostring | (capture("refs/heads/(?<branch>.+)").branch // .),
commit: .fromRef.latestCommit,
updated_at: .updatedDate | tostring
})
})
| map(select(if .title | test("wip"; "i") then false else true end))
| map(select(.updated_at >= '$version_updated_at'))
| sort_by(.updated_at)' >&3
elif [[ "$bitbucket_type" == "cloud" ]]; then
Expand All @@ -61,22 +63,27 @@ elif [[ "$bitbucket_type" == "cloud" ]]; then
while read -r pullrequest; do
branch=$(echo "$pullrequest" | jq -r '.source.branch.name')
id=$(echo "$pullrequest" | jq -r '.id')
title=$(echo "$pullrequest" | jq -r '.title')
commit=$(echo "$pullrequest" | jq -r '.source.commit.hash')
commit_url=$(echo "$pullrequest" | jq -r '.source.commit.links.self.href')

# get the commit date, which is when the PR last got updated code-wise.
# the updated_on field in the PR also changes when comment added etc
date=$(curl -s --fail -u "${username}:${password}" $commit_url | jq -r '.date')

prs+="+ [{id:\"$id\", branch: \"$branch\", commit:\"$commit\", updated_at:\"$date\"}]"
prs+="+ [{id:\"$id\", title: \"$title\", branch: \"$branch\", commit:\"$commit\", updated_at:\"$date\"}]"
done < <(jq -c '.[]' "${response}")

if [[ "$prs" == "[]" ]]; then
jq -n "$prs" >&3
exit
fi

# take the list of PRs | sort by update-date of commits | remove the date | pick latest PR, wrap as array for concourse
jq -n "[ $prs | sort_by(.updated_at) | map(del(.updated_at)) | .[-1] ]" >&3
# take the list of PRs | filter out containing "wip" in title | sort by update-date of commits | remove the date | pick latest PR, wrap as array for concourse
jq -n "[ $prs
| map(select(if .title | test('wip'; 'i') then false else true end))
| sort_by(.updated_at)
| map(del(.updated_at))
| .[-1] ]" >&3
fi

0 comments on commit 85299c6

Please sign in to comment.