Home > other >  Automated github issue bot?
Automated github issue bot?

Time:11-21

I would like to make a discord bot that creates an issue based on user input from discord. Any idea how I would do this? I am using JavaScript and would like to integrate it into an existing bot. Thanks!

CodePudding user response:

You can take ideas from the LeagueSandbox/IssueBot (Typescript), which does create issues.

It does use npmjs.com/package/github-api, from github-tools/github

export class IssueCommand extends Command {
  execute() {
    if(!this.args) {
      return
    }
    let issueBody = ISSUE_TEMPLATE
      .replace("{PLACEHOLDER}", this.args[2] || "_No content_")
      .replace("{CHANNEL}", this.message.channel.name)
      .replace("{USER}", this.message.author.username)
    Bot.gitHub.api.issues.create({
        owner: config.githubName,
        repo: this.args[0],
        title: this.args[1],
        body: <any>issueBody // Typings for the `github` package are incorrect, so we have to cast to any here.
      },
      (error, response) => this.handleGithubResponse(error, response)
    )
  }

  handleGithubResponse(error, response) {
    if(error) {
      let formattedError = JSON.stringify(error, null, 4)
      let reply = ERROR_TEMPLATE.replace('{PLACEHOLDER}', formattedError)
      this.message.reply(reply)
      return
    }
    let reply = SUCCESS_TEMPLATE.replace('{PLACEHOLDER}', response.html_url)
    this.message.reply(reply)
  }
}

You have to set up that bot in your Discord application.

CodePudding user response:

Maybe see the GitHub API docs for Creating Issues

You might need to create an app for it.

  • Related