"use strict"; // catch errors easier

const cfg = require("./config.js"); // config file
const addLabels = require("./issues/addLabels.js"); // add labels
const claimIssue = require("./issues/claimIssue.js"); // claim issue
const abandonIssue = require("./issues/abandonIssue.js"); // abandon issue
const removeLabels = require("./issues/removeLabels.js"); // remove labels
const issueAreaLabeled = require("./issues/issueAreaLabeled.js"); // issue labeled with area label
const checkPullRequestComment = require("./issues/checkPullRequestComment.js"); // check if comment belongs to PR
const joinLabelTeam = require("./issues/joinLabelTeam.js"); // join label team

module.exports = exports = function(payload) {
  // get necessary information from request body
  const action = payload.action;
  let commenter, body, addedLabel; // initialize variables for commenter, issue (comment) body, and added label
  if (action === "opened") { // if issue was opened
    commenter = payload.issue.user.login; // issue creator's username
    body = payload.issue.body; // contents of issue body
  } else if (action === "created") { // if issue comment was created
    commenter = payload.comment.user.login; // commenter's username
    body = payload.comment.body; // contents of issue comment
  } else if (action === "labeled") {
    addedLabel = payload.label.name;
  } else return;
  const issueLabelArray = payload.issue.labels;
  const issueNumber = payload.issue.number; // number of issue
  const issueCreator = payload.issue.user.login;
  const repoName = payload.repository.name; // issue repository
  const repoOwner = payload.repository.owner.login; // repository owner
  if (commenter === cfg.username) return;
  if (addedLabel && cfg.areaLabels) issueAreaLabeled(addedLabel, issueNumber, repoName, repoOwner, issueLabelArray); // check if issue labeled with area label
  if (!body) return; // if body is empty
  const commands = body.match(new RegExp("@" + cfg.username + "\\s(\\w*)", "g"));
  if (!commands) return; // if there is no command
  if (body.match(/#([0-9]+)/) && cfg.areaLabels) checkPullRequestComment(body, issueNumber, repoName, repoOwner); // check if comment is from PR
  commands.forEach((command) => {
    if (body.includes(`\`${command}\``) || body.includes(`\`\`\`\r\n${command}\r\n\`\`\``)) return;
    const commandName = command.split(" ")[1];
    if (commandName === "claim" && cfg.claimEnabled) claimIssue(commenter, issueNumber, repoName, repoOwner); // check body content for "@zulipbot claim"
    else if ((commandName === "abandon" || commandName === "unclaim") && cfg.abandonEnabled) abandonIssue(commenter, issueNumber, repoName, repoOwner); // check body content for "@zulipbot abandon" or "@zulipbot claim"
    else if (commandName === "label" && cfg.labelEnabled && cfg.selfLabelingOnly && commenter === issueCreator) {
      const splitBody = body.split(`@${cfg.username}`).filter((splitString) => {
        return splitString.includes(" label \"");
      }).join(" ");
      addLabels(splitBody, issueNumber, repoName, repoOwner, issueLabelArray); // check body content for "@zulipbot label" and ensure commenter opened the issue
    } else if (commandName === "remove" && cfg.removeEnabled && cfg.selfLabelingOnly && commenter === issueCreator) {
      const splitBody = body.split(`@${cfg.username}`).filter((splitString) => {
        return splitString.includes(" remove \"");
      }).join(" ");
      removeLabels(splitBody, issueNumber, repoName, repoOwner, issueLabelArray); // check body content for "@zulipbot remove" and ensure commenter opened the issue
    } else if (commandName === "join" && cfg.joinEnabled && cfg.areaLabels) {
      const splitBody = body.split(`@${cfg.username}`).filter((splitString) => {
        return splitString.includes(" join \"");
      }).join(" ");
      joinLabelTeam(splitBody, commenter, repoOwner, repoName, issueNumber); // check body content for "@zulipbot join"
    }
  });
};

@@ -31,16 +31,70 @@
 easier%0A%0A
+const github = require(%22./github.js%22); // config file%0A
 const cf
@@ -843,16 +843,312 @@
 action;%0A
+  const issueLabelArray = payload.issue.labels;%0A  const issueNumber = payload.issue.number; // number of issue%0A  const issueCreator = payload.issue.user.login;%0A  const repoName = payload.repository.name; // issue repository%0A  const repoOwner = payload.repository.owner.login; // repository owner%0A
   let co
@@ -1662,16 +1662,34 @@
 labeled%22
+ && cfg.areaLabels
 ) %7B%0A    
@@ -1727,519 +1727,498 @@
 ;%0A  
-%7D else return;%0A  const
+ 
  issue
+Area
 Label
-Array = payload.issue.labels;%0A  const issueNumber = payload.issue.number; // number of issue%0A  const issueCreator = payload.issue.user.login;%0A  const repoName = payload.repository.name; // issue repository%0A  const repoOwner = payload.repository.owner.login; // repository owner%0A  if (commenter === cfg.username) return
+ed(addedLabel, issueNumber, repoName, repoOwner, issueLabelArray); // check if issue labeled with area label%0A    return;%0A  %7D else if (action === %22closed%22) %7B%0A    const hasInProgressLabel = issueLabelArray.find(issueLabel =%3E issueLabel.name === cfg.inProgressLabel)
 ;%0A  
+ 
+ 
 if (
-addedLabel && cfg.area
+hasInProgress
 Label
-s
 ) 
-issueAreaLabeled(addedLabel, issueNumber, repoName, repoOwner, issueLabelArray); // check if issue labeled with area label
+github.issues.removeLabel(%7Bowner: repoOwner, repo: repoName, number: issueNumber, name: cfg.inProgressLabel%7D);%0A    return;%0A  %7D else return;%0A  if (commenter === cfg.username) return;
 %0A  i

Remove "in progress" label when issue is closed.