-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.sh
executable file
·73 lines (60 loc) · 1.98 KB
/
fetch.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
#!/bin/bash
function github-workflow() {
log "github-workflow called"
OWNER=$(get-config-i $1 OWNER)
REPO=$(get-config-i $1 REPO)
WF_NAME=$(get-config-i $1 WF_NAME)
URL=$(get-config-i $1 URL)
NAME=$(config-name $1)
if [ -z ${URL} ]; then
log "URL unset, fetching"
URL=$(curl -s -u ":$GH_PAT" -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$OWNER/$REPO/actions/workflows \
| jq -r ".workflows[] | select(.name == \"$WF_NAME\") | .url" \
2> $HOME/.cool-prompt/log)
set-config URL $URL $1
log "URL found $URL for $WF_NAME"
fi
curl -s -u ":$GH_PAT" -H "Accept: application/vnd.github.v3+json" $URL/runs \
2> $HOME/.cool-prompt/log \
1> "/tmp/$NAME"
jq -r '.workflow_runs[0].conclusion' "/tmp/$NAME" > "/tmp/${NAME}_last_status"
}
function gitlab-pipeline() {
log "gitlab-workflow called"
PROJECT_ID=$(get-config-i $1 PROJECT_ID)
NAME=$(config-name $1)
curl -s -H "PRIVATE-TOKEN: $GL_PAT" \
"https://gitlab.com/api/v4/projects/$PROJECT_ID/pipelines" \
2> $HOME/.cool-prompt/log \
1> "/tmp/$NAME"
jq -r '.[0].status' "/tmp/$NAME" > "/tmp/${NAME}_last_status"
}
function config-paths() {
log "config-paths called"
lsof -au $USER -d cwd -c bash -F n -w \
| grep -Po "(?<=n).*" \
| sort \
| uniq
}
log "fetch.sh called"
config-paths > ~/.cool-prompt/paths
echo "" > ~/.cool-prompt/wf_hosts
echo "" > ~/.cool-prompt/wf_dirs
while read dir; do
log "config directory $dir found"
cd $dir
echo $dir >> ~/.cool-prompt/wf_dirs
WF_HOST=($(get-config HOST))
for i in "${!WF_HOST[@]}"; do
echo "$(config-name $i)" >> ~/.cool-prompt/wf_hosts
host=${WF_HOST[$i]}
log "Dispatch $host workflow function"
case ${host} in
github) github-workflow $i ;;
gitlab) gitlab-pipeline $i ;;
*) echo "Unmatched ${host} : $dir [$i]" >> ~/.cool-prompt/log ;;
esac
done
done < <(tr ' ' '\n' < ~/.cool-prompt/paths)
# rm ~/.cool-prompt/paths