forked from joshjohanning/github-misc-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind-attachments-in-repositories.sh
More file actions
executable file
·75 lines (66 loc) · 2.44 KB
/
find-attachments-in-repositories.sh
File metadata and controls
executable file
·75 lines (66 loc) · 2.44 KB
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
#!/bin/bash
# Usage:
# ./find-attachments-in-repositories <org> <bool: GET_COMMENTS>
#
# Note:
# - The issues and comments API also bring in PRs
#
if [ -z "$2" ]; then
echo "Usage: $0 <org> <bool: GET_COMMENTS>"
echo "Example: ./find-attachments-in-repositories joshjohanning-org true"
exit 1
fi
ORG=$1
GET_COMMENTS=$2
repos=$(gh api --paginate /orgs/$ORG/repos --jq '.[].full_name')
for repo in $repos
do
echo "> looking through $repo ..."
prelim_issue_check=$(gh api --paginate /repos/$repo/issues --jq '.[].body' | grep -E "/assets/|/files/")
if [ "$prelim_issue_check" = "" ] ; then
echo " ... no issues found with attachments ..."
else
echo " ... found issues with attachments ..."
fi
if [ "$GET_COMMENTS" = true ] ; then
prelim_comment_check=$(gh api --paginate /repos/$repo/issues/comments --jq '.[].body' | grep -E "/assets/|/files/")
if [ "$prelim_comment_check" = "" ] ; then
echo " ... no comments found with attachments ..."
else
echo " ... found comments with attachments ..."
fi
else
prelim_comment_check=""
fi
if [ "$prelim_issue_check" = "" ] && [ "$prelim_comment_check" = "" ] ; then
continue
else
# check for issues
if [ "$prelim_issue_check" != "" ]; then
issues=$(gh api --paginate /repos/$repo/issues --jq '.[].number')
for issue in $issues
do
issue_content=$(gh api /repos/$repo/issues/$issue)
if echo "$issue_content" | jq '.body' | grep -qE "/assets/|/files/"; then
echo "$issue_content" | jq -r '.html_url'
fi
done
fi
# check comments
if [ "$GET_COMMENTS" = true ] && [ "$prelim_comment_check" != "" ]; then
# we have to get issues again
issues=$(gh api --paginate /repos/$repo/issues --jq '.[].number')
for issue in $issues
do
comments=$(gh api --paginate /repos/$repo/issues/$issue/comments --jq '.[].id')
for comment in $comments
do
comment_content=$(gh api /repos/$repo/issues/comments/$comment)
if echo "$comment_content" | jq '.body' | grep -qE "/assets/|/files/"; then
echo "$comment_content" | jq -r '.html_url'
fi
done
done
fi
fi
done