Skip to content

Instantly share code, notes, and snippets.

@rpalmite
Forked from styx/glpr.sh
Created April 26, 2018 12:19
Show Gist options
  • Save rpalmite/67883d4bf5247a80433af319c9eeb08a to your computer and use it in GitHub Desktop.
Save rpalmite/67883d4bf5247a80433af319c9eeb08a to your computer and use it in GitHub Desktop.
Create Gitlab pull request from command line
#!/bin/bash
BROWSER='google-chrome'
#GITLAB_SECRET=''
ENDPOINT='http://gitlab.activeby.net/api/v3'
PROJECT='activebilling/core'
#curl --header "PRIVATE-TOKEN: xxx" "http://gitlab.activeby.net/api/v3/projects/activebilling%2Fcore" | awk '{match($1,"[0-9]+",a)}END{print a[0]}'
PROJECT_ID=177
ACTION="projects/$PROJECT_ID/merge_requests"
CURRENT_BRANCH=`git branch | grep '^\*' | awk '{ print $2; }'`
git push --set-upstream origin $CURRENT_BRANCH || (echo "Failed to push\n" && exit 1)
MERGE_REQUEST_ID=$(curl -s --header "PRIVATE-TOKEN: $GITLAB_SECRET" --data "source_branch=$CURRENT_BRANCH&title=$CURRENT_BRANCH&target_branch=master" "$ENDPOINT/$ACTION" | grep -o '"iid":[0-9]\+' | grep -o '[0-9]\+')
$($BROWSER "http://gitlab.activeby.net/$PROJECT/merge_requests/$MERGE_REQUEST_ID") 2>/dev/null
echo "http://gitlab.activeby.net/$PROJECT/merge_requests/$MERGE_REQUEST_ID/diffs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment