commit 6b36560b6df1ba46ca600421d1e2d585c6fae894 Author: Dan Ballard Date: Sat Jul 7 13:33:49 2018 -0500 initial import of gogs-notify script and a Docerkfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d1093bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:3.8 + +RUN apk add --no-cache ca-certificates curl + +COPY gogs-notify / + +ENTRY-POINT [/gogs-notify] diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a59bac --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +Create a user on Gogs for posting build notifications (like 'buildbot') and generate a token for it. Insert the token as a drone secret. + + drone secret add dan/gogs-notify-test --name gogs_account_token --value $VALUE --event pull-request --event push --event tag --event deployment + +Use in drone.yml: + + notify-gogs: + image: drone-gogs + when: + event: pull_request + secrets: [gogs_account_token] + gogs_url: https://git.openprivacy.ca + + diff --git a/gogs-notify b/gogs-notify new file mode 100644 index 0000000..d71ba87 --- /dev/null +++ b/gogs-notify @@ -0,0 +1,15 @@ +#!/bin/sh + +URL="$GOGS_URL/api/v1/repos/${DRONE_REPO}/issues/${DRONE_PULL_REQUEST}/comments" + +RESULT=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GOGS_ACCOUNT_TOKEN" -H "Content-Type: application/json" -d "{\"Body\": \"Drone Build Status: ${DRONE_BUILD_STATUS}\n\n${DRONE_BUILD_LINK}\"}" -X POST $URL) +CURL_RESULT=$? + +if [ $RESULT -eq 201 ] +then + echo "Success posting to $URL" +else + echo "ERROR posting to $URL" + echo "ERROR http: $RESULT curl: $CURL_RESULT" + exit 1 +fi