Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@styx
Last active June 20, 2019 05:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save styx/9387062 to your computer and use it in GitHub Desktop.
Save styx/9387062 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"
@Shuliyey
Copy link

how did you generate the gitlab_secret, is this your own gitlab server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment