-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-submission-prs.sh
executable file
·153 lines (113 loc) · 4.64 KB
/
generate-submission-prs.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# Open PRs for slackbuilds submitted via the form on the slackbuilds.org website.
set -e
set -o pipefail
if ! command -v go-github-apps > /dev/null 2>&1 ; then
printf 'This scripts needs "go-github-apps". (https://github.com/nabeken/go-github-apps)\n'
exit 1
fi
if ! command -v gh > /dev/null 2>&1 ; then
printf 'This scripts needs "gh". (https://github.com/cli/cli)\n'
exit 1
fi
BOT_NAME="sbo-bot[bot]"
BOT_ID="143931017"
GIT_REPO=SlackBuildsOrg/slackbuilds
APP_INSTALLATION_ID=41634818
ORIGPWD="$(pwd)"
CWD="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
TMP_FOLDER="$(mktemp -d)"
trap 'cd "$ORIGPWD" && rm -rf "$TMP_FOLDER"' INT TERM HUP QUIT EXIT
# shellcheck source=/dev/null
GITHUB_TOKEN="$(source "$CWD/../.env" && GITHUB_PRIV_KEY="$(echo -e "$PRIVATE_KEY")" go-github-apps -app-id "$APP_ID" -inst-id "$APP_INSTALLATION_ID")"
export GITHUB_TOKEN
printf 'Syncing data...\n'
(
cd "$TMP_FOLDER"
rsync -avPSH slackbuilds.org:/slackbuilds/www/pending/ pending
gh repo clone "https://github.com/$GIT_REPO.git" slackbuilds -- --depth=1
cd slackbuilds
git config --local commit.gpgsign false
git config --local user.name "$BOT_NAME"
git config --local user.email "[email protected]"
)
{
find "$TMP_FOLDER/pending" -name '*.tar*' -type f -maxdepth 1 -printf '%T@ %p\0' | sort -zk 1n | sed -z 's/^[^ ]* //' | xargs -0 -I xx basename xx | sed 's/\.tar.*$//' | while read -r package ; do
printf "Checking submission %s\n" "$package"
checksum="$(md5sum "$TMP_FOLDER/pending"/"$package".tar* | awk '{ print $1 }')"
(
cd "$TMP_FOLDER/slackbuilds/"
git checkout master
git reset --hard origin/master
git checkout -b "$package-$checksum"
)
found="$(find "$TMP_FOLDER/slackbuilds" -type d -name "$package" -maxdepth 2 -mindepth 2 \! -path '*/.git/*')"
if [ "" = "$found" ] ; then
printf 'New submission found %s\n' "$package"
printf 'Please find the submission email and enter the category: '
read -u 3 -r category
printf 'Now please enter the short description for the commit message. Only the part which will appear between the brackets: '
read -u 3 -r msg
dir="$package"
(
cd "$TMP_FOLDER/slackbuilds/$category"
rm -rf "$dir"
tar -xf "$TMP_FOLDER/pending"/"$package".tar*
cd "$dir"
chmod 0644 -- *SlackBuild
# shellcheck source=/dev/null
. "$dir".info
git add .
git commit --author "$MAINTAINER <$EMAIL>" -m "$category/$PRGNAM: Added ($msg)." --no-verify
)
else
printf 'Update for an existing script found %s => %s\n' "$package" "$found"
dir="$(basename "$found")"
category="$(basename "$(dirname "$found")")"
(
cd "$TMP_FOLDER/slackbuilds/$category"
cd "$dir"
# shellcheck source=/dev/null
. "$dir".info
cd ..
OLD_VERSION="$VERSION"
rm -rf "$dir"
tar -xf "$TMP_FOLDER/pending"/"$package".tar*
cd "$dir"
chmod 0644 -- *SlackBuild
# shellcheck source=/dev/null
. "$dir".info
git add .
if [ "$VERSION" = "$OLD_VERSION" ] ; then
printf 'Looks like the version did not change. Please enter the commit message: '
read -u 3 -r msg
git commit --author "$MAINTAINER <$EMAIL>" -m "$category/$PRGNAM: $msg." --no-verify
else
git commit --author "$MAINTAINER <$EMAIL>" -m "$category/$PRGNAM: Updated for version $VERSION." --no-verify
fi
)
fi
(
cd "$TMP_FOLDER/slackbuilds"
git push --set-upstream "https://$BOT_NAME:[email protected]/$GIT_REPO.git" HEAD
gh pr create --repo="$GIT_REPO" --head "$package-$checksum" --label submission-form --fill-first
)
ssh -n [email protected] "mv ~/www/pending/$package.tar* ~/ARCHIVE/"
(
cd "$TMP_FOLDER/slackbuilds"
pr_number="$(gh pr list --repo="$GIT_REPO" --head "$package-$checksum" --json number --jq '.[].number')"
printf 'Successfully created a PR for %s with number %s\n' "$category/$dir" "$pr_number"
printf "Would you like to schedule a build for %s: " "$category/$dir"
read -u 3 -r answer
if [ "$answer" = "y" ] || [ "$answer" = "yes" ] ; then
printf "I'll output the PR diff now. Please inspect it *carefully*:\n"
gh pr diff --repo="$GIT_REPO" "$pr_number"
printf "Really queue builds? "
read -u 3 -r answer
if [ "$answer" = "y" ] || [ "$answer" = "yes" ] ; then
gh pr comment --repo="$GIT_REPO" "$pr_number" --body "@sbo-bot: build $category/$dir"
fi
fi
)
done
} 3<&0