通过脚本,发起分支合并请求和打tag

#!/bin/bash

Set GitLab API URL and access token

GITLAB_API_URL="http://IP/api/v4"

ACCESS_TOKEN="Token秘钥"

Define repository IDs

declare -A repo_ids=(

"git@IP:kingmq/client.git"="123"

"git@IP:kingmq/server.git"="456"

)

Function: Create a merge request

create_merge_request() {

local repo=$1

local src_branch=$2

local dest_branch=$3

local title=$4

local description=$5

local repo_id={repo_ids\[repo]}

echo "Creating a merge request from src_branch to dest_branch for repository $repo"

Make API request to create a merge request

response=(curl -s --request POST --header "PRIVATE-TOKEN: ACCESS_TOKEN" --data "source_branch=src_branch\&target_branch=dest_branch&title=title\&description=description" "GITLAB_API_URL/projects/repo_id/merge_requests")

Parse the response to get the merge request URL

merge_request_url=(echo "response" | python -c 'import sys, json; print(json.load(sys.stdin)"web_url")')

echo "Merge request created: $merge_request_url"

}

create_tag() {

local repo=$1

local branch=$2

local tag_name=$3

local tag_message=$4

local repo_id={repo_ids\[repo]}

echo "Creating tag tag_name on branch branch for repository $repo"

获取分支的提交 SHA

commit_sha=(curl -s --header "PRIVATE-TOKEN: ACCESS_TOKEN" "GITLAB_API_URL/projects/repo_id/repository/branches/$branch" | python -c 'import sys, json; print(json.load(sys.stdin)"commit""id")')

创建标签

response=(curl -s --request POST --header "PRIVATE-TOKEN: ACCESS_TOKEN" --data "tag_name=tag_name\&ref=commit_sha&message=tag_message" "GITLAB_API_URL/projects/$repo_id/repository/tags")

echo "Tag created: $response"

}

Interactive repository selection

select_repo() {

PS3="Select a repository: "

select repo in "kingmq-client" "kingmq-common" "kingmq-kmf" "kingmq-server" "Exit"; do

case $repo in

"Exit")

exit 0

;;

*)

break

;;

esac

done

repo_url="git@IP:XXX/$repo.git"

}

main(){

echo -e "输入 \n\

1: Merge from release to main \n\

4: release分支打标签 \n\

其他:取消"

read -p "请输入 " args

case $args in

title="合并release到main"

description="合并release到main"

select_repo

create_merge_request "repo_url" "release" "main" "title" "$description"

;;

echo "请输入tag编号:"

read version

title="$version"

description="baseline-$version"

select_repo

create_tag "repo_url" "release" "title" "$description"

;;

*)

echo "Invalid option: $1"

echo "Usage: $0 {1|2}"

exit 1

;;

esac

}

#开始执行

main $*

相关推荐
阿里嘎多学长4 小时前
2026-07-10 GitHub 热点项目精选
开发语言·程序员·github·代码托管
今夕资源网11 小时前
AI声音克隆软件 CosyVoice今夕一键整合包解压即用 阿里巴巴通义实验室开源 github斩获22K星标
人工智能·github·多国语言·声音克隆·零样本语音克隆·感情·ai语音克隆
胡萝卜术13 小时前
从聊天模型到本地执行助手:Remote MCP 多工具 Agent 实战
面试·架构·github
慕容引刀15 小时前
告别Commit信息纠结:使用Git AI Commit插件实现规范化提交
人工智能·git·github·visual studio code·visual studio
GoGeekBaird1 天前
我开源了 BeeWeave,给 AI Agent 搭一个越用越懂你的知识创作台
后端·github
fthux1 天前
GitZip Pro 源码解析:一个 GitHub 文件/文件夹下载扩展是如何工作的(一)整体架构与扩展入口
人工智能·ai·开源·github·open source
第一程序员1 天前
Rust Agent 子进程执行:Command 之前,先定义输入和超时
python·rust·github
2501_936960361 天前
GitHub初步了解
github
wangruofeng1 天前
11 万 Star 的生成式 AI 入门课,Microsoft 做对了什么
github·aigc·ai编程
IOT那些事儿1 天前
GitHub Profile 429: Too Many Requests
github·profile·429