gpt4 book ai didi

jira - 使用 GitLab API 设置外部问题跟踪器设置?

转载 作者:行者123 更新时间:2023-12-05 01:30:00 25 4
gpt4 key购买 nike

我将 GitLab 与外部问题跟踪器 (JIRA) 结合使用,并且运行良好。

我的问题是当我创建一个新的 GitLab 项目(使用 API)时,我必须进入 GitLab 的项目设置并手动选择我想使用的问题跟踪器并手动 输入我的外部问题跟踪器的项目 ID。

这个画面会比较有说服力: GitLab external issue tracker settings
(来源:bayimg.com)

(我说的两个字段是“Issue tracker”和“Project name or id in issues tracker”)

所以这是我的问题:有没有办法使用 API 或其他方式自动设置这两个字段?目前,GitLab API没有提及有关外部问题跟踪器设置的任何内容。

最佳答案

此代码帮助我自动设置 GitLab 的外部问题跟踪器设置,使用 Apache HttpClientJsoup .这段代码绝对不是 100% 好,但它展示了主要思想,即重新创建 Web 表单发送的相应 POST 请求。

// 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();
}

更改 _NAMESPACE_/_PROJECT_NAME_ 使其与您的项目 URL 相对应,将 _MY_PRIVATE_TOKEN_ 更改为您管理员帐户的 token ,并将 _MY_JIRA_PROJECT_NAME_ 更改为 . .. 您的 jira 项目名称。

关于jira - 使用 GitLab API 设置外部问题跟踪器设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23514118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com