通过脚本,发起分支合并请求和打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 小时前
2024年12月18日Github流行趋势
github
hunteritself4 小时前
AI Weekly『12月16-22日』:OpenAI公布o3,谷歌发布首个推理模型,GitHub Copilot免费版上线!
人工智能·gpt·chatgpt·github·openai·copilot
pubuzhixing6 小时前
开源白板新方案:Plait 同时支持 Angular 和 React 啦!
前端·开源·github
玖疯子12 小时前
如何详细地遵循RustDesk的步骤来搭建远程访问和自定义服务器?
github
小华同学ai13 小时前
ShowDoc:Star12.3k,福利项目,个人小团队的在线文档“简单、易用、轻量化”还专门针对API文档、技术文档做了优化
前端·程序员·github
loop lee1 天前
Nginx - 负载均衡及其配置(Balance)
java·开发语言·github
粥里有勺糖1 天前
视野修炼第114期 | 2024JS现状调查结果
前端·javascript·github
o(╥﹏╥)2 天前
github如何给本机绑定 ssh密钥(MACOS)
运维·gitee·ssh·github
ct10270385272 天前
github快速查找已被删除的文件指令日志
运维·github
vvw&2 天前
如何在 Linux 服务器上部署 Pydio Cells 教程
linux·运维·服务器·自动化·debian·github·私有化部署