npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

slack-github-issue-creator

v2.2.1

Published

Wouldn't it be cool to automate the process of creating Github issues directly from Slack messages?

Downloads

17

Readme

Slack Github issue creator

Wouldn't it be cool to automate the process of creating Github issues directly from Slack messages? Just use this library and you are sorted!

PS! Supports Github Enterprise as well :)

Setup

Github token

  • create personal access token - go to https://github.com/settings/tokens, click "Generate new token"
  • give it reasonable name
  • in "Select scopes" section make sure to check repo (and all subscopes), read:org and user (and all subscopes)
  • click "Generate token", store safely the value which is displayed on the screen, we will need to use it later

Slack application

  • go to "Your apps" - https://api.slack.com/apps

  • click "Create new app"

  • fill in your app name, select Slack workspace where you would like to have this app available

  • in "Basic information" screen you should see Client ID, secret and other credentials. Store "Signing secret" safely, we will need to use it later

  • go to "Interactivity & shortcuts". Change the toggle position to "On"

  • figure out what will be the url of your application - we will need "BASE_URL" value in the next steps

  • in "Request URL" field provide following value "https://BASE_URL/create-github-issue"

  • in "Select Menus" field provide following value "https://BASE_URL/external-select"

  • in "Shortcuts" section click "Create New Shortcut", in the new screen choose "On messages". Give it reasonable name and short description - it will be displayed later in your Slack workspace. In "Callback ID" field type "create_issue".

  • go to "OAuth&Permissions" menu

  • in "Scopes" section click "Add an OAuth scope" under "Bot Token Scopes" and add "commands" scope.

  • add also "users:read" scope

  • go to "Install app" menu

  • click "Install App to Workspace". In the new screen click "Allow".

  • Slack will display "Bot User OAuth Access Token". Store it safely, we will need to use it later

Slash command

It is possible to use this app as a slash command bot. If configured properly, when you type /your-slash-command you will see empty modal that allows you to fill in Github issue details.

docs/empty-modal.png

You can also define issue title as a part of slash command. Type /your-slash-command This is the issue title.

docs/modal-with-title.png

In order to configure this:

  • on Slack open your app settings
  • click "Slash commands" on the left hand side menu
  • click "Create new command"
  • in "Command" input define your command (in my case - it's create-github-issue)
  • define request url with following value: "https://BASE_URL/slash-command"
  • optionally - define "Short description" and "Usage Hint"
  • press "Save" and test it in your Slack workspace

Your app

  • install this package as dependency in your app - npm install --save slack-github-issue-creator
  • in your index.js file:
const express = require('express');
const createServer = require('slack-github-issue-creator');

const app = express();
const port = Number(process.env.PORT) || 3000;

const config = {
    githubToken: process.env.GITHUB_API_TOKEN,
    githubBaseUrl: 'https://api.github.com',
    slackApiToken: process.env.SLACK_API_TOKEN,
    slackSigningSecret: process.env.SLACK_SIGNING_SECRET,
    channelMap: {},
};

app.use(createServer(config));

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
  • GITHUB_API_TOKEN - token created in "Github token" section
  • SLACK_API_TOKEN - Bot User OAuth Access Token created when the app was installed to your workspace
  • SLACK_SIGNING_SECRET - the value can be found in "Basic information" screen in your app, it is described also a bit above :)

optionally you might want to change "githubBaseUrl", if your company uses Github Enterprise. The url then should be (most probably) https://YOUR_GITHUB_URL/api

Channel map

It is possible to pass channelMap object in config. Let's assume that you have #internal-dev-team Slack channel and you use this addon very often there. You do not want to search for repository every team, when you click "Create github issue". So you can deliver predefined map in the config object to map this channel to specific repo.

Example:

const config = {
    // ...
    channelMap: {
        CHANNEL_ID: {
            name: 'my-github-org/my-repo',
            value: 'MDEwOlJlcG9zaXRvcnkzMTAwMDgzNDU=',
        },
    },
};

CHANNEL_ID can be found in the channel url. Open Slack app in your browser, navigate to your channel and use the id from url. Example:

https://app.slack.com/client/T018YKBP4EL/C01T7PLL13N -> C01T7PLL13N is the channel id

how to get this magic hash for your repo?

  • open your repo in the browser and then open source code
  • find <meta name="hovercard-subject-tag"> html attribute
  • it might look like this: <meta name="hovercard-subject-tag" content="repository:310008345" data-pjax-transient="">
  • calculate base64 string for the value 010:RepositoryREPO_ID - where REPO_ID is an integer that is a part of content attribute of html tag. In my case - 010:Repository310008345. And the base64 string is MDEwOlJlcG9zaXRvcnkzMTAwMDgzNDU=

Testing

Deploy your application, make sure you set your Slack application to have correct urls.

Go to Slack, hover over a message and click three dots icon. Then click "More message shortcuts..." and type the shortcut name you've chosen for your shortcut (it was done in "Interactivity & shortcuts" / "Shortcuts" in your app settings).

Assuming you've set everything properly, you should be able to see screen like this:

docs/shortcut.png

Choose repository, fill in other details and press "Submit". You should get the notification that your issue is now created 🎉