k19810703 / JiraGitLabAPI

如何调用Jira和Gitlab的RestAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JiraGitLabAPI

Jira

Jira的API有多种认证方式,最简单的是用Basic Auth的方式,请参考
https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/
简单来说就是把用户名密码按user:password的方式做base64加密,然后设置在HTTP头部即可
node.js代码例

var request = require("request");
var jiraoptions ={ method: 'POST',
    url: 'http://jiurl:jiraport/rest/api/2/issue/'+issueid+'/transitions',
    headers: {'Content-Type': 'application/json',
        Authorization: 'Basic 加密后的user:password==' },
    body: { 请求主体 },
    json: true };
request(jiraoptions, function (error, response, body) {
    if (error) throw new Error(error);
    res.status(200).end();
});

API文档请参考
https://docs.atlassian.com/DAC/rest/jira/6.1.html#d2e1074

Gitlab

Gitlab可以使用private token的方式,token可以在settings->access token里发行,在HTTP请求头里加上'PRIVATE-TOKEN': 'access token'即可
node.js代码例

var request = require("request");
var options = {
        method: 'POST',
        url: 'http://gitlaburl:gitlabport/api/v4/projects/29/repository/branches',
        headers:{'PRIVATE-TOKEN': 'accesstoken'},
        formData: { 请求参数 };
request(options, function (error, response, body) {
    if (error) throw new Error(error);
});

API文档请参考
https://docs.gitlab.com/ee/api/README.html

About

如何调用Jira和Gitlab的RestAPI