通过脚本,发起分支合并请求和打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 $*

相关推荐
穆梓兰煊36 分钟前
AI 供应链安全:模型制品签名校验与 Redis 缓存落地
github
简创AIGC陶先生39 分钟前
【直播切片工作台】第17章:JWT 鉴权:签发、解析与中间件
github
Funlang40 分钟前
Fun 的工具链,自己写自己
github
云南新人和数采集团1 小时前
DeepSeek Harness 开源贡献手记:从入门到合入主线
python·开源·github
曹牧2 小时前
电子邮件服务器拒绝了您的用户名
github
wflynn3 小时前
GitHub 今日推荐|Snapintosh:用 ARM EL2 监控器骗过内核,让骁龙芯片笔记本跑 macOS
python·开源·github
钱栈up3 小时前
GitHub 热榜上手|ArtCraft:+13,572 star 的 AI 创作 IDE
人工智能·github
阿里嘎多学长4 小时前
2026-10-23 GitHub 热点项目精选
开发语言·程序员·github·代码托管
Brookty5 小时前
Git 与 GitHub|第一阶段:仓库、版本历史与 Git 对象模型(上篇)
git·github
miofly5 小时前
GitHub 日榜趋势速报 | 2026-10-24
开源·github