0

For Probot issue comments create functionality, Probot is creating multiple comments as a loop when the bot created a comment as "Improper command. Please follow the syntax: /label [add/remove], label1, label2, label3". Here is the code:

app.on("issue_comment.created", async (context) => {
    context.log('issue comment has been created')
    const user_type = context.payload.comment.user.type
    context.log("comment was created by: ", user_type)

    if (context.payload.comment.user.type === 'User') {
      context.log('comment was created by a user')
      
      commands(app, 'label', (context, command) => {
        context.log(command)
        const labelvals  = command.arguments.split(/, */);
        context.log(labelvals)
        var labels_len  = labelvals.length
        context.log('label_len '+ labels_len);
        var labels  = labelvals.slice(1, labels_len);

        context.log(labels);
        
        if(labelvals[0].includes("add") && labels_len > 1) {
          context.log(labels);
          context.octokit.issues.addLabels(context.issue({ labels }));
          return;
        }
        else if (labelvals[0].includes("remove") && labels_len > 1) {
           context.octokit.issues.removeLabel(context.issue({ name: labels[0] }));
           return;
        }
        else if (labels_len <= 1) {
          const params  = context.issue({ body: "Improper command. Please follow the syntax: /label [add/remove], label1, label2, label3" });
          context.octokit.issues.createComment(params);
          return;
        }
      })
    }
    else{
      context.log('comment was created by a Bot')
      return;
    }
  });

enter image description here

I am expecting to see only one comment from bot, but sometimes bot throwing more than 3 at a time.

0 Answers0