omsf-eco-infra / ticgithub

Tools to use a GitHub repository as a support ticket system
MIT License
0 stars 0 forks source link
github github-actions gmail-inbox ticketing-system

ticgithub

Tools to use a GitHub repository as a support ticket system.

We had a shared inbox that didn't get a lot of traffic (not enough to justify spending \$​\$​\$​\$ on email ticketing solutions), but it was essential that all emails that came in there get a timely response.

Essentially, our needs were:

The solution proposed here is to use GitHub issues as the ticket management system. This allows assignment and notifications as normal on GitHub. GitHub Actions workflows are used to check email and post any new email as issues, and to ping the team if issues haven't been closed/assigned.

Setup

Ingredients:

Inbox setup

Some current workflows make use of some GMail-specific IMAP extensions (specifically, labels), and therefore only GMail is fully supported.

To use your existing GMail account, you will need to provide an app password, which currently requires enabling two-factor authentication. You will also need to enable IMAP in your account. In detail:

  1. Enable IMAP the for GMail account associated with your inbox.
  2. Turn on two-factor authentication for that Google account.
  3. Add an app password. Use a custom name; the value of the name does not matter (e.g, you can use "ticgithub" or "Support Repository" or anything else you want). Record that password; you will need to add it as a GitHub secret later.
  4. Create labels in your account to represent assignment. I recommend nested labels under the assigned label, e.g., assigned/dwhswenson.

Bot setup

The bot consists of an optional SMTP account and a GitHub user account. The bot's SMTP account is used to send emails to the team (e.g., to reply in-thread to provide a link to the relevant GitHub issue). It is probably logical in most cases for the bot to have its own email address, and for that to be the email address used to register the bot's GitHub account.

You will need to:

  1. Create an email account for the bot. If using GMail, you will have to go through the steps of setting up an app password as described under "Inbox setup."
  2. Create a GitHub account for the bot.

After you have created the repository (see below), you will also need to create a personal access token with

Repository setup

This is just a standard GitHub repository. Current approach assumes that all issues are support tickets that should be managed by the bot (with reminders, etc.) so at this stage it is recommended that this repository be kept separate from the core development repository. The repository can be private, although the usage of ticgithub workflows will subtract from your allotted GitHub Actions minutes for the month.

To set up the repository:

  1. Create the repository.
  2. Give your bot write access to the repository.
  3. Create the bot's personal access token (PAT), giving access to the repository. This will need to be done from within the bot's GitHub account.
  4. Add the secrets to the GitHub repository. The names of the secrets are customizable, and will be the inputs to the configuration file, but you will need a secret to store each of:

    • the app password for your inbox
    • the password for your bot's SMTP account (if using sendmail functionality)
    • the bot's PAT with write access to the repository

Configuration

ticgithub is configured with a YAML file stored at .ticgithub.yml in the root directory of your issues repository. This file consists of two main groups of settings: config, which defines the inbox, bot, and your team, and workflows, which provides specific instructions for the workflows that are installed with the python -m ticgithub.build command.

Inbox configuration

The inbox is the mailbox that you want to turn into GitHub issues. It has the following entries:

Bot configuration

The bot performs the actions of writing to the repository and sending emails back shared inbox to link to new repository issues. As such, you must define both a GitHub user for the bot and a sendmail user for the bot. If you do not use the sendmail functionality (reply-inbox: active: false) you still must define the sendmail information but it need not be valid. For example, you can use user: foo and secret: not_registered_in_github.

Team configuration

The team parameter under config is a list of team members. Each team member should have the following keys:

Workflow configuration

Each workflow is a key within workflows in the .ticgithub.yml. The name of the key must match the name of the workflow.

emails-to-issues

This is the workflow that converts your inbox into GitHub issues. It is a scheduled workflow, but can also be run manually using the workflow_dispatch event.

Its parameters are:

unassigned-reminder

This workflow posts a comment to remind that an open issue has remained unassigned after some period of time. It is a scheduled workflow, but can also be run manually using the workflow_dispatch event.

Its parameters are:

unclosed-reminder

This workflow posts a comment to remind that an assigned issue hasn't been closed after some period of time. It is a scheduled workflow, but can also be run manually using the workflow_dispatch event.

Its parameters are:

assignment-to-gmail

This workflow is triggered immediately when an issue is assigned.

Its parameters are:

Build-time vs. run-time configuration

Some parameters are used during the ticgithub.build process to create the GHA workflows. These parameters are build-time parameters. Others are used from within the workflow run. These are run-time parameters.

If changing build-time parameters, you will need to rerun the ticgithub.build process. If unsure, rerunning ticgithub.build will never cause problems, and might update your workflows for new changes.

Most parameters are run-time parameters. The exceptions are:

"Installation" / Usage

Once you have created your .ticgithub.yml file, you can use ticgithub to create the GHA workflows based on your configuration. On your local machine, in a clone of your issues repository, install ticgithub into the current environment:

python -m pip install ticgithub

From the root directory of your clone of the issues repository, run the command:

python -m ticgithub.build

This will create the relevant workflows. Ensure that they are added in a git commit and push up to your default branch, and you'll have ticgithub up and running!

Running tasks locally

You can run any of the built-in tasks locally as well. To do this, use, e.g.,

python -m ticgithub.tasks.emails_to_issues

You will need to have environment variables set for your GitHub Actions secrets. To do this temporarily on the command line, just preface the command by setting the variables temporarily:

INBOX_PASSWORD="password" SENDMAIL_PASSWORD="password" BOT_TOKEN="token" python -m ticgithub.tasks.emails_to_issues

You can select choose a dry run by passing --dry. You can select a specific configuration file (other than ./.ticgithub.yml) with --config or -c.

The assignment-to-gmail task takes an additional parameter for the issue number, e.g,

python -m ticgithub.tasks.assignment_to_gmail --dry 99

Customizing the build process

The build process can be further customized based on a build config YAML file. The default build config is at ticgithub/data/build_config.yml. This allows customization of the files generated by the build command. There are two categories of customization: customization of ticgithub itself, and customization of the individual workflows, under the builders heading.

Under the ticgithub heading:

The builders heading contains a list where each item is a workflow. For each workflow, the following keys should be included: