当前位置: 首页 > news >正文

使用Python3实现Gitee码云自动化发布

仓库信息

https://gitee.com/liumou_site/ip

实现代码

import osimport requests
from loguru import loggerdef gitee(ver, message, prerelease: bool = False):"""在 Gitee 上创建发布版本:param ver: 版本号:param message: 发布信息:param prerelease: 是否为预发布版本,默认为 False:return: 无"""# 配置信息GITEE_ACCESS_TOKEN = os.getenv('GITEE_ACCESS_TOKEN')if GITEE_ACCESS_TOKEN is None:print("请设置环境变量 GITEE_ACCESS_TOKEN")exit(1)logger.debug("GITEE_ACCESS_TOKEN: " + GITEE_ACCESS_TOKEN)OWNER = 'liumou_site'REPO = 'ip'TAG_NAME = f'v{ver}'NAME = f'Version {ver}'# 构建请求 URLurl = f'https://gitee.com/api/v5/repos/{OWNER}/{REPO}/releases'# 构建请求体data = {'tag_name': TAG_NAME,'name': NAME,'body': message,'target_commitish': 'master','owner': OWNER,'repo': REPO,'prerelease': prerelease,'access_token': GITEE_ACCESS_TOKEN}# 发送 POST 请求response = requests.post(url, data=data)# 检查响应if response.status_code == 201:logger.info('Release created successfully!')logger.info(response.json())else:logger.error(f'Failed to create release: {response.status_code}')logger.error(response.text)logger.error(response.request)exit(2)if __name__ == '__main__':gitee(ver='1.0.9', message='master', prerelease=False)

效果

"D:\Program Files\Python313\python.exe" D:\code\gitee\go\ip\gitee.py 
2024-11-21 10:36:57.933 | DEBUG    | __main__:gitee:21 - GITEE_ACCESS_TOKEN: 7ac..........
2024-11-21 10:36:58.406 | INFO     | __main__:gitee:48 - Release created successfully!
2024-11-21 10:36:58.407 | INFO     | __main__:gitee:49 - {'id': 450710, 'tag_name': 'v1.0.9', 'target_commitish': '28a5383f0cc7103546c805100b4a0d68e40547c8', 'prerelease': False, 'name': 'Version 1.0.9', 'body': 'master', 'author': {'id': 1785140, 'login': 'liumou_site', 'name': '坐公交也用券', 'avatar_url': 'https://foruda.gitee.com/avatar/1673661977951995067/1785140_liumou_site_1673661977.png', 'url': 'https://gitee.com/api/v5/users/liumou_site', 'html_url': 'https://gitee.com/liumou_site', 'remark': '', 'followers_url': 'https://gitee.com/api/v5/users/liumou_site/followers', 'following_url': 'https://gitee.com/api/v5/users/liumou_site/following_url{/other_user}', 'gists_url': 'https://gitee.com/api/v5/users/liumou_site/gists{/gist_id}', 'starred_url': 'https://gitee.com/api/v5/users/liumou_site/starred{/owner}{/repo}', 'subscriptions_url': 'https://gitee.com/api/v5/users/liumou_site/subscriptions', 'organizations_url': 'https://gitee.com/api/v5/users/liumou_site/orgs', 'repos_url': 'https://gitee.com/api/v5/users/liumou_site/repos', 'events_url': 'https://gitee.com/api/v5/users/liumou_site/events{/privacy}', 'received_events_url': 'https://gitee.com/api/v5/users/liumou_site/received_events', 'type': 'User'}, 'created_at': '2024-11-21T10:36:58+08:00', 'assets': [{'browser_download_url': 'https://gitee.com/liumou_site/ip/archive/refs/tags/v1.0.9.zip', 'name': 'v1.0.9.zip'}, {'browser_download_url': 'https://gitee.com/liumou_site/ip/archive/refs/tags/v1.0.9.tar.gz', 'name': 'v1.0.9.tar.gz'}]}进程已结束,退出代码0

在这里插入图片描述

官方接口

Gitee接口

http://www.lryc.cn/news/489054.html

相关文章:

  • Ubuntu24.04下的docker问题
  • PAT (Basic Level) Practice (中文)1002 写出这个数
  • C07.L07.STL之映射.应用2.统计数字
  • 微信小程序组件详解:text 和 rich-text 组件的基本用法
  • 算法.图论-习题全集(Updating)
  • this.$prompt 限制输入长度
  • JDBC使用p6spy记录实际执行SQL方法【解决SQL打印两次问题】
  • 问题: redis-高并发场景下如何保证缓存数据与数据库的最终一致性
  • Stable Diffusion核心网络结构——CLIP Text Encoder
  • C语言-11-18笔记
  • 数据结构_图的遍历
  • 设计LRU缓存
  • python中的base64使用小笑话
  • Python之time时间库
  • Easyexcel(4-模板文件)
  • 国产linux系统(银河麒麟,统信uos)使用 PageOffice 动态生成word文件
  • Window11+annie 视频下载器安装
  • SAP GR(Group Reporting)配置篇(七)
  • 共建智能软件开发联合实验室,怿星科技助力东风柳汽加速智能化技术创新
  • 优化表单交互:在 el-select 组件中嵌入表格显示选项
  • 每日一题 LCR 079. 子集
  • cocos creator 3.8 Node学习 3
  • 微信小程序底部button,小米手机偶现布局错误的bug
  • 【计组】复习题
  • Apache Maven 标准文件目录布局
  • Android 功耗分析(底层篇)
  • 【Xbim+C#】创建圆盘扫掠IfcSweptDiskSolid
  • IntelliJ+SpringBoot项目实战(四)--快速上手数据库开发
  • 利用oss进行数据库和网站图片备份
  • Excel - VLOOKUP函数将指定列替换为字典值