This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathkata-find-stale-skips.sh
executable file
·125 lines (92 loc) · 2.51 KB
/
kata-find-stale-skips.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
# Description: Look for tests that are currently being skipped, but which
# should no longer be (since the issue they are being skipped on is now
# closed).
set -e
readonly script_name=${0##*/}
info()
{
local -r msg="$*"
echo "INFO: $msg"
}
usage()
{
cat <<EOF
Usage: $script_name [-h | --help | help]
Options:
--help : Show this help text.
-h :
help :
Description: Look for tests in the current repository that contain "skips"
[1]. If the test specifies a skip containing a GitHub issue URL, check its state
since if the issue is (now) closed, the skip is stale and can be removed.
The advantage of removing skips is to increase test coverage and reduce test
code that is not being exercised.
---
[1] - A skip is a test which has been marked as disabled so that it is not
currently run.
EOF
}
# Determine if the specified github issue is closed.
#
# Warning: This function uses the github API which is rate-limited!
#
# Paramters:
#
# $1 - full URL (in form https://github.com/$org/$repo/issues/$number)
#
# Returns:
#
# - "yes" if issue is closed.
# - "no" if issue is not closed.
is_github_issue_closed()
{
local -r url="$1"
# Convert URL to the API equivalent, which returns a JSON document.
local -r api_url=$(echo "$url" | sed -e 's|github.com|api.github.com/repos|')
# Extract issue state from JSON
local state=$(curl -sL "$api_url" |\
grep '"state" *:' |\
cut -d: -f2- |\
tr -d '"' |\
tr -d , |\
tr -d " ")
[ "$state" = "closed" ] && echo yes && return
echo "no"
}
check_skips()
{
[ -n "$1" ] && usage && exit 0
results=$(mktemp)
# Get a list of files that contain skips
grep -ir "skip.*https://github.com/.*/issues/[0-9][0-9]*" > "$results"
[ ! -e "$results" ] && info "No skipped tests" && rm -f "$results" && return
count=$(cut -d: -f1 < "$results"|sort -u|wc -l)
info "Found $count tests containing skips"
# Extract a unique list of URL from the skip files
urls=$(xurls "$results"|sort -u)
url_count=$(echo "$urls"|wc -l)
info "Found $url_count skip URLs"
for url in $urls
do
info "Checking skip URL $url"
closed=$(is_github_issue_closed "$url")
if [ "$closed" = "yes" ]
then
# Get a list of files that specify this skip URL
files=$(grep "$url" "$results"|cut -d: -f1|sort -u)
info "Remove skip from following files (issue $url is closed):"
info
for file in $files
do
info " $file"
done
info
fi
done
rm -f "$results"
}
check_skips "$@"