forked from allanpedroni/otc-vsts-agent-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preconditions
64 lines (57 loc) · 2.2 KB
/
preconditions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
set -e
source <(otc-task-include lib/git.sh)
source <(otc-task-include lib/assert.sh)
source <(otc-task-include lib/vsts.sh)
source <(otc-task-include lib/console.sh)
source <(otc-task-include lib/azure-pipelines-yaml-protection.sh)
source <(otc-task-include lib/vsts-pr.sh)
source <(otc-task-include lib/vsts-pr-statuses.sh)
# Param lines_threshold
# Param ignore_lines_pattern
# Param diff_filter_args (--) ...
# Required environment variables:
# - SYSTEM_PULLREQUEST_PULLREQUESTID
function capture-pr-size-and-perform-size-validation
{
local lines_threshold="$1"
local ignore_lines_pattern="$2"
shift 2
local diff_filter_args="$@"
assert-not-empty lines_threshold
assert-not-empty ignore_lines_pattern
assert-not-empty SYSTEM_PULLREQUEST_PULLREQUESTID
local pullrequest_id=$SYSTEM_PULLREQUEST_PULLREQUESTID
local changed_lines_report_json=$(count-changed-lines \
$(get-base-branch) \
"$ignore_lines_pattern" "$diff_filter_args")
echo -n "Changed lines details: "
echo $changed_lines_report_json
echo "Adding changed lines data to PR properties collection ..."
pullrequest-update-properties "$pullrequest_id" "$changed_lines_report_json"
local changed_lines=$(echo $changed_lines_report_json | \
jq -M '.filtered.insertions + .filtered.deletions - .filtered.comments_or_blank_lines')
# Performing size validation in order to define as PR status
echo "Considering (.filtered.insertions + .filtered.deletions - .filtered.comments_or_blank_lines) (= $changed_lines)"
local status='succeeded'
if [ "$changed_lines" -gt "$lines_threshold" ]
then
status='failed'
red "Pull request size ($changed_lines lines) exceeds threshold ($lines_threshold)."
else
green "Pull request size ($changed_lines lines) under threshold ($lines_threshold)."
fi
pullrequest-set-size-status "$pullrequest_id" "$status" "$changed_lines" "$lines_threshold"
}
function show-modified-items
{
git-diff-prepare $(get-base-branch)
echo "Modified items without filter:"
echo "Add Rem"
git diff --numstat $(get-base-branch)
}
assert-not-empty SYSTEM_PULLREQUEST_PULLREQUESTID
reset-pr-statuses $SYSTEM_PULLREQUEST_PULLREQUESTID
show-modified-items
azure-pipelines-yaml-protection
capture-pr-size-and-perform-size-validation "$@"