Skip to content

Instantly share code, notes, and snippets.

@stigok stigok/gogs-issue
Last active Jun 12, 2017

What would you like to do?
Create new issue in git repository on Gogs server instance
# Create an issue on a Gogs repo specified by pwd's git remote
# Exit codes:
# 1 : Missing env
# 2 : Curl error
# 3 : JSON parsing error
# Get a key at https://<gogs-server-url>/user/settings/applications
# Fail if missing env
if [ -z "$api_server" ]; then
echo >&2 'GOGS_SERVER_URL is an empty string'
exit 1
if [ -z "$api_key" ]; then
echo >&2 'GOGS_SERVER_API_KEY is an empty string'
exit 1
set -e
remote_url="$(git remote get-url origin | grep -oE '[a-z]+/[a-z]+')"
org="$(echo $remote_url | cut -d '/' -f1)"
name="$(echo $remote_url | cut -d '/' -f2)"
body="you can do it"
# Print issue list when no args
if [ -z "$title" ]; then
result=$(curl -s \
-H 'Content-Type: application/json' \
if [ $? -ne 0 ]; then
>&2 echo "Failed to list issues (curl exited with $?)"
exit 2
node -e "const obj = JSON.parse('$result'); obj.forEach(x => console.log(x.number, x.title)); if (!obj.length) console.log('No issues in repo')" && exit 0
exit 3
# Create a new issue with args as title
result=$(curl -s \
-H 'Content-Type: application/json' \
-d "{\"title\":\"$title\",\"body\": \"$body\", \"labels\": []}" \
-X POST "${api_server}/api/v1/repos/$org/$name/issues?token=$api_key" \
| jsonprop number)
if [ $? -ne 0 ]; then
>&2 echo "Failed to create new issue (curl exited with $?)"
exit 2
# Print URL of the new issue
echo $api_server/$remote_url/issues/$result

This comment has been minimized.

Copy link
Owner Author

stigok commented Jun 12, 2017

Depends on Node.js for JSON parsing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.