我将 GitLab 与外部问题跟踪器 (JIRA) 一起使用,并且效果很好。
我的问题是当我创建一个新的 GitLab 项目(使用 API)时,我必须进入 GitLab 的项目设置并manually选择我想要使用的问题跟踪器并manually输入我的外部问题跟踪器的项目 ID。
This screen will be more eloquent:
(source: bayimg.com http://image.bayimg.com/9f43dcebf9a03c03e711b0e208d9e46ca95d6781.jpg)
(我说的两个领域是“问题跟踪器" and "问题跟踪器中的项目名称或 ID")
所以这是我的问题:有什么方法可以设置这两个字段自动地,使用API还是其他?现在,亚搏体育appGitLab API https://docs.gitlab.com/ce/api/README.html没有提及任何有关外部问题跟踪器设置的内容。
这段代码帮助我自动设置 GitLab 的外部问题跟踪器设置,使用Apache HttpClient https://hc.apache.org/ and Jsoup http://jsoup.org/。
这段代码绝对不是100%好,但它显示了主要思想,即重新创建相应的POST
Web 表单发送的请求。
// 1 - Prepare the HttpClient object :
BasicCookieStore cookieStore = new BasicCookieStore();
LaxRedirectStrategy redirectStrategy = new LaxRedirectStrategy();
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.setRedirectStrategy(redirectStrategy)
.build();
try {
// 2 - Second you need to get the "CSRF Token", from a <meta> tag in the edit page :
HttpUriRequest getCsrfToken = RequestBuilder.get()
.setUri(new URI("http://localhost/_NAMESPACE_/_PROJECT_NAME_/edit"))
.build();
CloseableHttpResponse responseCsrf = httpclient.execute(getCsrfToken);
try {
HttpEntity entity = responseCsrf.getEntity();
Document doc = Jsoup.parse(EntityUtils.toString(entity));
String csrf_token = doc.getElementsByAttributeValue("name", "csrf-token").get(0).attr("content");
// 3 - Fill and submit the "edit" form with new values :
HttpUriRequest updateIssueTracker = RequestBuilder
.post()
.setUri(new URI("http://localhost/_NAMESPACE_/_PROJECT_NAME_"))
.addParameter("authenticity_token", csrf_token)
.addParameter("private_token", "_MY_PRIVATE_TOKEN_")
.addParameter("_method", "patch")
.addParameter("commit", "Save changes")
.addParameter("utf8", "✓")
.addParameter("project[issues_tracker]", "jira")
.addParameter("project[issues_tracker_id]", "_MY_JIRA_PROJECT_NAME_")
.addParameter("project[name]", "...")
...
.build();
CloseableHttpResponse responseSubmit = httpclient.execute(updateIssueTracker, httpContext);
} finally {
responseCsrf.close();
}
} finally {
httpclient.close();
}
Change _NAMESPACE_/_PROJECT_NAME_
要使其与您的项目 URL 相对应,请更改_MY_PRIVATE_TOKEN_
使用您的管理员帐户的令牌,然后更改_MY_JIRA_PROJECT_NAME_
与...您的 jira 项目的名称。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)