因为工作需要对数程序跑完之后,自动的告知一下大家,并把结果上传到gitlab的issue下。所以给对数工具添加了一下脚本。
用的是python-gitlab,详细可以看看这个文档,直接上代码。
class GitlabProject(object):
def __init__(self, url, token,project_id):
self.gl = gitlab.Gitlab(url, private_token=token)
self.project = self.gl.projects.get(project_id)
def create_issue(self,title,desc):
issue = self.project.issues.create({'title': title,
'description': desc})
return issue
# issue下加comment
def create_note(self,issue,content):
note = issue.notes.create({'body': content})
return note
# issue下上传对数结果
def upload_file_to_note(self,issue,file):
uploaded_file = self.project.upload("result.zip", filepath=file)
issue.notes.create({
"body": "See the [对数结果]({})".format(uploaded_file["url"])
})
附上,压缩文件夹的方法,https://blog.csdn.net/wangtua/article/details/68943231