Youtrack工作流无缘无故地抛出http库异常

时间:2019-04-01 23:13:49

标签: javascript discord webhooks

这是工作流程代码。它不断抛出异常,但没有指出异常的原因。 我试图删除(见下文)http库调用,然后它起作用了。奇怪的是它在没有更改lib调用的情况下就已经起作用了。

 * This is a template for an on-change rule. This rule defines what
 * happens when a change is applied to an issue.
 *
 * For details, read the Quick Start Guide:
 * https://www.jetbrains.com/help/youtrack/incloud/2019.1/Quick-Start-Guide-Workflows-JS.html
 */

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var http = require('@jetbrains/youtrack-scripting-api/http');

exports.rule = entities.Issue.onChange({
  // TODO: give the rule a human-readable title
  title: 'discord-notification-in-progress',
  guard: function(ctx) {
    console.log("checking if state became InProgress");
    return ctx.issue.fields.becomes(ctx.State, ctx.State.InProgress);
  },
  action: function(ctx) {
    console.log("executing POST to discord");
    var assignee = ctx.issue.fields.Assignee.login;
    var url = ctx.issue.url;
    console.log(assignee);
    var id = ctx.issue.id;
    var summary = ctx.issue.summary;
    var data = {
      "username": "CoopR YouTrack Info",
      "content": "**" + assignee + "** is now working on " + id + ": " + summary + " (" + url + ")"
    };
    console.log(data);
    var connection = new http.Connection('https://discordapp.com');
    connection.addHeader('Content-Type', 'application/json');

    connection.postSync('/api/webhooks/xxx/1DJucC8-vdZR-xxx', [], data);

  },

  requirements: {
    State: {
      type: entities.State.fieldType,
      name: "State",
      InProgress: {
        name: "In Progress"
      }
    },
    Assignee: {
      type: entities.User.fieldType
    }
  }
});

这是一个例外:

Processing issue COOPR-70:
TypeError: Cannot call method "getContent" of null (@jetbrains/youtrack-scripting-api/http#119)
             org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4198)
            org.mozilla.javascript.gen.coopr_discord_notification_notificate_in_progress_3686._c_anonymous_2(coopr-discord-notification/notificate-in-progress:34)

当我删除这些行时:

var connection = new http.Connection('https://discordapp.com');
    connection.addHeader('Content-Type', 'application/json');

    connection.postSync('/api/webhooks/xxx/1DJucC8-vdZR-xxx', [], data);

一切都很好-奇怪的是-以前没有更改任何东西

0 个答案:

没有答案