Created
September 2, 2016 14:42
-
-
Save EkkoG/806028215f2444c790770e281ffe94fc to your computer and use it in GitHub Desktop.
From https://wiki.imciel.com/sandry/%E5%91%BD%E4%BB%A4%E8%A1%8C%E6%8F%90%E4%BA%A4gitlab_merge_request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() | |
{ | |
echo "usage: 使用命令行提交 Merge Request,参数如下: | |
-p 源工程 ID | |
-s 源工程分支 | |
-d 目标工程 ID | |
-t 目标工程分支 | |
-u 用户 ID | |
-m Merge Request 标题 | |
相关 ID 请使用 gitlab 命令查找" 1>&2; | |
exit 1; | |
} | |
if command -v gitlab >/dev/null 2>&1; then | |
echo "exists gitlab" > /dev/null 2>&1 | |
else | |
echo 'gitlab 不存在,请安装,https://github.com/NARKOZ/gitlab' | |
fi | |
export GITLAB_API_ENDPOINT="http://gitlab.example.com/api/v3" | |
if [ "${GITLAB_API_PRIVATE_TOKEN}x" == "x" ];then | |
echo "请设置 Gitlab private token,若无 private token,请到 http://gitlab.example.com/profile/personal_access_tokens 生成" | |
fi | |
# 默认目标工程 ID | |
des_project="222" | |
# 默认源工程 ID | |
source_project="233" | |
# 默认目标分支 | |
des_branch="develop" | |
# 默认目标分支 | |
source_branch="develop" | |
# 默认提交用户 | |
current_user="68" | |
while getopts ":s:t:p:m:u:d:" o | |
do | |
case "${o}" in | |
d) | |
des_project=${OPTARG} | |
;; | |
p) | |
source_project=${OPTARG} | |
;; | |
s) | |
source_branch=${OPTARG} | |
;; | |
t) | |
des_branch=${OPTARG} | |
;; | |
u) | |
current_user=${OPTARG} | |
;; | |
m) | |
message=${OPTARG} | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
# 标题必填 | |
if [ "${message}x" == "x" ];then | |
echo "请填写 Merge request 标题" | |
exit 1; | |
fi | |
# 得到 gitlab 命令行的输出 | |
output=$(gitlab create_merge_request ${source_project} "${message}" "{ source_branch: '${source_branch}', target_branch: '${des_branch}', assignee_id: ${current_user}, target_project_id: ${des_project}}" --json) | |
# 如查包含 created_at 字符串,则表示提交成功,失败时输出日志 | |
success=$(echo ${output} | grep "created_at") | |
if [ "${success}x" == "x" ];then | |
echo ${output} | |
else | |
echo "提交成功" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment