如何使用REST API(NodeJS)将工作日志添加到Jira Issue?

时间:2019-01-09 16:48:11

标签: node.js jira jira-rest-api

我正在创建一个加载项,该加载项应自动创建工作日志。我正在使用node-js(jira-connector)。 我设法获取问题,并创建新的问题,但出现错误:

  

UnhandledPromiseRejectionWarning:错误:缺少“ worklog”属性   当我想将工作日志添加到问题中

   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。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。我直接通过REST呼叫(POST)发送输入。为此,我正在使用“请求”

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