如何使用 REST API (NodeJS) 将工作日志添加到 Jira Issue?
How to add worklog to Jira Issue using REST API (NodeJS)?
我正在创建一个应该自动创建工作日志的插件。我正在使用节点 js(jira 连接器)。
我设法解决问题并创建新问题,但出现错误:
UnhandledPromiseRejectionWarning: Error: Missing 'worklog' property
when I want to add worklogs to a Issue
function updateIssueInJira()
{
var jira = getoAuth();
try {
return new Promise(() => {
jira.issue.addWorkLog({
opts: {
issueKey: 'NTS-4',
adjustEstimate: 'new',
newEstimade: '2d',
worklog: 'Testing'
}
})
});
} catch (error) {
console.log(error);
}
}
addWorkLog的定义是:
/**
* Adds a new worklog entry to an issue.
*
* @method addWorkLog
* @memberOf IssueClient#
* @param {Object} opts The options to pass to the API. Note that this object must contain EITHER an issueId or
* issueKey property; issueId will be used over issueKey if both are present.
* @param {string} [opts.issueId] The id of the issue. EX: 10002
* @param {string} [opts.issueKey] The Key of the issue. EX: JWR-3
* @param {string} [opts.adjustEstimate] Allows you to provide specific instructions to update the remaining time
* estimate of the issue. Valid values are
* * "new" - sets the estimate to a specific value
* * "leave"- leaves the estimate as is
* * "manual" - specify a specific amount to increase remaining estimate by
* * "auto"- Default option. Will automatically adjust the value based on the
* new timeSpent specified on the worklog
* @param {string} [opts.newEstimate] (required when "new" is selected for adjustEstimate) the new value for the
* remaining estimate field. e.g. "2d"
* @param {string} [opts.reduceBy] (required when "manual" is selected for adjustEstimate) the amount to reduce the
* remaining estimate by e.g. "2d"
* @param {Object} opts.worklog See {@link: https://docs.atlassian.com/jira/REST/latest/#d2e1106}
* @param [callback] Called after the worklog is added.
* @return {P
romise} Resolved after the worklog is added.
*/
this.addWorkLog = function (opts, callback) {
if (!opts.worklog) {
throw new Error(errorStrings.NO_WORKLOG_ERROR);
}
var options = this.buildRequestOptions(opts, '/worklog', 'POST', opts.worklog, {
newEstimate: opts.newEstimate,
reduceBy: opts.reduceBy,
adjustEstimate: opts.adjustEstimate
});
return this.jiraClient.makeRequest(options, callback, 'Worklog Added');
};
在 getoAuth() 下,我正在进行 oAuth 身份验证,我想将工作日志添加到 Issue NTS-4。
我找到了解决办法。我正在通过 REST 调用 (POST) 直接发送输入。为此,我使用 'request'
function updateIssueInJira(oauth)
{
var testjson = {
author: {
emailAddress: "myemail"
},
comment: "Test",
timeSpentSeconds: "2700"
}
request.post({
url:'https://thelocation.com/rest/api/2/issue/ISSUEKEY/worklog/',
oauth:oauth,
json:true,
body: testjson
},
function (e, r, user) {
console.log(user)
});
}
我正在创建一个应该自动创建工作日志的插件。我正在使用节点 js(jira 连接器)。 我设法解决问题并创建新问题,但出现错误:
UnhandledPromiseRejectionWarning: Error: Missing 'worklog' property when I want to add worklogs to a Issue
function updateIssueInJira()
{
var jira = getoAuth();
try {
return new Promise(() => {
jira.issue.addWorkLog({
opts: {
issueKey: 'NTS-4',
adjustEstimate: 'new',
newEstimade: '2d',
worklog: 'Testing'
}
})
});
} catch (error) {
console.log(error);
}
}
addWorkLog的定义是:
/**
* Adds a new worklog entry to an issue.
*
* @method addWorkLog
* @memberOf IssueClient#
* @param {Object} opts The options to pass to the API. Note that this object must contain EITHER an issueId or
* issueKey property; issueId will be used over issueKey if both are present.
* @param {string} [opts.issueId] The id of the issue. EX: 10002
* @param {string} [opts.issueKey] The Key of the issue. EX: JWR-3
* @param {string} [opts.adjustEstimate] Allows you to provide specific instructions to update the remaining time
* estimate of the issue. Valid values are
* * "new" - sets the estimate to a specific value
* * "leave"- leaves the estimate as is
* * "manual" - specify a specific amount to increase remaining estimate by
* * "auto"- Default option. Will automatically adjust the value based on the
* new timeSpent specified on the worklog
* @param {string} [opts.newEstimate] (required when "new" is selected for adjustEstimate) the new value for the
* remaining estimate field. e.g. "2d"
* @param {string} [opts.reduceBy] (required when "manual" is selected for adjustEstimate) the amount to reduce the
* remaining estimate by e.g. "2d"
* @param {Object} opts.worklog See {@link: https://docs.atlassian.com/jira/REST/latest/#d2e1106}
* @param [callback] Called after the worklog is added.
* @return {P
romise} Resolved after the worklog is added.
*/
this.addWorkLog = function (opts, callback) {
if (!opts.worklog) {
throw new Error(errorStrings.NO_WORKLOG_ERROR);
}
var options = this.buildRequestOptions(opts, '/worklog', 'POST', opts.worklog, {
newEstimate: opts.newEstimate,
reduceBy: opts.reduceBy,
adjustEstimate: opts.adjustEstimate
});
return this.jiraClient.makeRequest(options, callback, 'Worklog Added');
};
在 getoAuth() 下,我正在进行 oAuth 身份验证,我想将工作日志添加到 Issue NTS-4。
我找到了解决办法。我正在通过 REST 调用 (POST) 直接发送输入。为此,我使用 'request'
function updateIssueInJira(oauth)
{
var testjson = {
author: {
emailAddress: "myemail"
},
comment: "Test",
timeSpentSeconds: "2700"
}
request.post({
url:'https://thelocation.com/rest/api/2/issue/ISSUEKEY/worklog/',
oauth:oauth,
json:true,
body: testjson
},
function (e, r, user) {
console.log(user)
});
}