Skip to main content
 首页 » 编程设计

python之对 Stash 标签的删除请求

2025年02月15日9mate10pro

这个问题类似于Git delete branch without cloning?总体来说非常简单,但出于某种原因我找不到正确的答案。

我正在使用 Stash REST API 更新 Stash 存储库中的标签。发送 POST 请求和添加新标签很容易(例如使用 python 请求,但可以与 curl 相同):

#!/usr/bin/python3.5 
 
import requests 
 
url = '.../rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags' 
 
data = {'force': 'false', 
        'message': 'Updated tag', 
        'name': 'LATEST_SUCCESSFUL', 
        'startPoint': 'ffffff', 
        'type': 'LIGHTWEIGHT'} 
 
headers = {'Content-Type': 'application/json', 
           'X-Atlassian-Token': 'no-check'} 
 
r = requests.post(url, data=data, header=headers) 

这工作正常,但我想保留远程删除此标签的选项。根据文档https://developer.atlassian.com/static/rest/stash/3.11.6/stash-scm-git-rest.html?_ga=1.6600434.1354597480.1483944905这应该有效:

url = '.../rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/LATEST_SUCCESSFUL 
r = requests.delete(url) 

但是我在这里遇到 404 错误。那么问题来了,访问(和删除)单个标签的正确方法是什么?

请您参考如下方法:

答案原来很简单,因为标签删除请求应该命中

rest/git/1.0/... 

代替

rest/api/1.0/... 

但后者对于 get 请求工作正常。