我正在尝试更新别人的python代码。在
我需要从Bitbucket中提取一个源(分支)列表,以允许用户从该列表中进行选择。现有代码成功地使用URL请求从Bitbucket中检索项目和存储库的列表,但是我找不到一种方法来访问源位置,从默认的“主”更改为用户选择的分支。作为参考,这段代码摘录用于提取存储库信息:
@app.route("/initial3" , methods=['GET', 'POST'])
def initial3():
selected_git_project = str(request.form.get('git_project'))
selected_git_repository = str(request.form.get('git_information'))
#checkbox_all_selection = str(request.form.get('checkbox_all'))
confluence_information = [str(request.form.get('confluence_information'))]
selected_page = request.form.get('page_id')
returnlistsearch = []
url = 'https://git.ourcompanyname.com/rest/api/1.0/projects/'+selected_git_project+'/repos/'+selected_git_repository+'/files?limit=1000'
resources_json = requests.get(url, auth=(git_user, git_password)).json()
resources_json_dump = (json.dumps(resources_json, indent=4, sort_keys=False))
decoded = json.loads(resources_json_dump)
for x in decoded['values']:
if '.robot' in x:
location=os.path.dirname(x)
if location!='':
returnlistsearch.append(location)
returnlistsearch =remove_duplicated(returnlistsearch)
return render_template('initial3.html',git_repository=selected_git_repository,git_project=selected_git_project ,git_information=returnlistsearch)
我想我可以重用相同的代码,但是需要修改URL(关于atlassian文档似乎表明这是可行的):
^{pr2}$任何建议都将不胜感激-我第一次看python是在两天前。在
如果您不必通过http请求来完成,我建议您使用GitPython库。您可以使用它来访问任何存储库。在
Here is the tutorial, how to use it.
经过大量的尝试和错误之后,我发现了有效的语法。分支引用应用于HTTP请求的末尾。在
检索分支信息:
检索分支中的文件列表:
^{pr2}$相关问题 更多 >
编程相关推荐