Skip to content

Commit

Permalink
Merge pull request #63 from NJUPT-SAST/dev-xun
Browse files Browse the repository at this point in the history
Add: add webhook script & modify action file.
  • Loading branch information
Xunop authored Nov 4, 2023
2 parents f90d0df + 1dbb92c commit dcce9f3
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,21 @@ jobs:
TARGET: ${{ secrets.REMOTE_TARGET }}
SCRIPT_AFTER: |
sudo systemctl restart sastlink.service
- name: Send Success Message
if: ${{ success() }}
run: |
bash ../../scripts/webhook.sh \
-u "https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks/${{ github.run_id }}" \
-w ${{ secrets.WEBHOOK_URL }} \
-s sast_link -c "${{github.event.pull_request.user.login}}" -f 'success' \
-m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}"
- name: Send Fail Message
if: ${{ fail() }}
run: |
bash ../../scripts/webhook.sh \
-u "https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks/${{ github.run_id }}" \
-w ${{ secrets.WEBHOOK_URL }} \
-s sast_link -c "${{github.event.pull_request.user.login}}" -f 'false' \
-m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}"
14 changes: 12 additions & 2 deletions api/v1/oauth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,16 @@ func Authorize(c *gin.Context) {
reqLog.LogReq(r)
err := srv.HandleAuthorizeRequest(w, r)
clients, _ := srv.Manager.GetClient(r.Context(), r.Form.Get("client_id"))
log.Log.Println(clients)
var item ClientStoreItem
if err := clientAdapter.SelectOne(c, &item, fmt.Sprintf("SELECT * FROM %s WHERE id = $1", "oauth2_clients"), r.Form.Get("client_id")); err != nil {
log.Log.Errorf("----DEBUG----: %s", err.Error())
log.Log.Printf("\nau :: client: %s\n", item)
log.Log.Printf("\nau :: client_id: %s\n", r.Form.Get("client_id"))
log.Log.Errorf("----DEBUG----: %s", err.Error())
return
}
log.Log.Printf("\nau :: client: %s\n", clients)
log.Log.Printf("\nau :: client_id: %s\n", r.Form.Get("client_id"))
if err != nil {
c.JSON(http.StatusInternalServerError, result.Failed(result.InternalErr.Wrap(err)))
return
Expand Down Expand Up @@ -266,7 +275,8 @@ func AccessToken(c *gin.Context) {
// TODO: DEBUG
if err := clientAdapter.SelectOne(c, &item, fmt.Sprintf("SELECT * FROM %s WHERE id = $1", "oauth2_clients"), id); err != nil {
log.Log.Errorf("----DEBUG----: %s", err.Error())
log.Log.Printf("\nitem: %v\n", item)
log.Log.Printf("\nat :: client: %s\n", item)
log.Log.Printf("\nat :: client_id: %s\n", r.Form.Get("client_id"))
return
}

Expand Down
89 changes: 89 additions & 0 deletions scripts/webhook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

usage() {
echo "Usage: $0 [-u <workflow_url>] [-w <webhook_url>] [-s <service_name>] [-c <commit_user>] [-m <commit_url>] [-f <flow_status>]" 1>&2
exit 1
}

while getopts "hu:w:s:c:m:f:" arg; do
case $arg in
h)
usage
;;
u)
workflow_url="$OPTARG"
;;
w)
webhook_url="$OPTARG"
;;
s)
service_name="$OPTARG"
;;
c)
commit_user="$OPTARG"
;;
m)
commit_url="$OPTARG"
;;
f)
flow_status="$OPTARG"
;;
?)
usage
;;
esac
done

if [[ -z "$workflow_url" || -z "$webhook_url" || -z "$service_name" || -z "$commit_user" || -z "$commit_url" || -z "$flow_status" ]]; then
usage
exit 1
fi

status="success"
if systemctl is-active --quiet "$service_name"; then
echo "service $service_name is running"
status="success"
else
echo "service $service_name is not running"
status="failed"
fi

# GMT time
cur_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

card_msg='{
"msg_type": "interactive",
"card": {
"elements": [{
"tag": "div",
"text": {
"content": "[Commit]('$commit_url') by '$commit_user'",
"tag": "lark_md"
}
}, {
"actions": [{
"tag": "button",
"text": {
"content": "see details",
"tag": "lark_md"
},
"url": "'$workflow_url'",
"type": "default",
"value": {}
}],
"tag": "action"
}],
"header": {
"title": {
"content": "'$service_name' workflows run '$flow_status' at '$cur_date'\nService status: '$status'",
"tag": "plain_text"
}
}
}
}'

echo $card_msg

curl -X POST -H "Content-Type: application/json" \
-d "$card_msg" \
"$webhook_url"

0 comments on commit dcce9f3

Please sign in to comment.