Package: ticgithub
ticgithubTools 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 ability to assign an email to an individual, and to notify that person
that they have been assigned.The ability to see, at a glance, what emails were missing assignment.Some automation to ensure that we're reminded of any unassigned emails.Some automation to ensure that tickets are being closed in a timely fashion
once they've been assigned.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.SetupIngredients:Aninboxwhere you receive support emails. Currently must be GMail.Abotwhich consists of a GitHub user account and (optionally) an SMTP
account.Arepositoryto host your support tickets.Inbox setupSome 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:Enable IMAPthe for GMail
account associated with your inbox.Turn on two-factor
authenticationfor that
Google account.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.Create labels in your account to represent assignment. I recommend nested
labels under theassignedlabel, e.g.,assigned/dwhswenson.Bot setupThe 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: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."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 withRepository setupThis 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 ofticgithubworkflows will subtract from your allotted GitHub
Actions minutes for the month.To set up the repository:Create the repository.Give your bot write access to the repository.Create the bot'spersonal access token
(PAT),
giving access to the repository. This will need to be done from within the
bot's GitHub account.Add the
secretsto 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 inboxthe password for your bot's SMTP account (if using sendmail functionality)the bot's PAT with write access to the repositoryConfigurationticgithubis configured with a YAML file stored at.ticgithub.ymlin 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, andworkflows, which provides specific instructions for the workflows that are
installed with thepython -m ticgithub.buildcommand.Inbox configurationThe inbox is the mailbox that you want to turn into GitHub issues. It has the
following entries:type: currently, must begmailuser: the username, e.g.,inboxaddress@gmail.comsecret: the name of the GitHub secret containing the app passwordhost: for gmail,imap.gmail.comBot configurationThe 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 informationbut it need not be valid. For example, you can
useuser: fooandsecret: not_registered_in_github.token_name: name of the GitHub secret containing the bot's PAT (possibly
restricted to a single repo)repo: full name (owner/repository) for the repository this bot should be
managing.sendmail: sendmail user info, containing of a dict with the following:user: sendmail username, e.g.,botaddress@gmail.comsecret: name of the GitHub secret containing the sendmail passwordhost: sendmail hostname, e.g.,smtp.gmail.comTeam configurationTheteamparameter underconfigis a list of team members. Each team member
should have the following keys:github: GitHub username, e.g.,dwhswensonemail: sufficient part of the email to uniquely identify the user (doesn't
have to be the full email), e.g.,david.swensonlabel: label creating in the Gmail inbox to indicate that this user has
been assigned, e.g.,assigned/dwhswensonWorkflow configurationEach workflow is a key withinworkflowsin the.ticgithub.yml.  The name of
the key must match the name of the workflow.active: Boolean determining whether or not the workflow is active. If the
workflow is listed in the configuration andactiveis not explicitly
listed, it is assumed thatactive == true.dry: Boolean determining whether to do a dry run. Defaultfalseemails-to-issuesThis is the workflow that converts your inbox into GitHub issues.
It is a scheduled workflow, but can also berun
manuallyusing theworkflow_dispatchevent.Its parameters are:active: Boolean determining whether or not the workflow is active. If the
workflow is listed in the configuration andactiveis not explicitly
listed, it is assumed thatactive == true.dry: Boolean determining whether to do a dry run. Defaultfalsecron: crontab entry for when this workflow should be runfilters: list of filters to exclude emails from creating issues, options
are:bot filter: filters out emails send from the bot's sendmail addressname: botactive: whether to use the filter; defaulttrueteam filter: whether to filter emails from the team but not directly to
(i.e., CC'd, BCC'd to) the inboxname: teamactive: whether to use the filter; defaulttrueomitted senders filter: filter emails that include specific stringsname: omit-sendersactive: whether to use the filter; defaulttruesenders: list of strings; any sender that matches this string will not
generate an issuerecent: time delta indicating how recently (rounded down to the day)
emails should be loaded.
Parameters match those ofdatetime.timedelta(i.e.,days,hours,minutes,seconds, ...)reply-inbox: parameters for sending a reply to the inbox to indicate that
a GitHub issue has been created for this emailactive: whether to send the email; defaulttruetemplate: a file in thestring.Templateformat for the reply email.
Allowed keys:$GITHUB_URL: the URL for the issueunassigned-reminderThis 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 berun
manuallyusing theworkflow_dispatchevent.Its parameters are:active: Boolean determining whether or not the workflow is active. If the
workflow is listed in the configuration andactiveis not explicitly
listed, it is assumed thatactive == true.dry: Boolean determining whether to do a dry run. Defaultfalsecron: crontab entry for when this workflow should be runemail-ticket-only: whether to only comment on issues that appear to have
been created from by theemails-to-issuestask.delay: time delta, any issues without assignment that have been open for
longer than this time will trigger a reminder comment.
Parameters match those ofdatetime.timedelta(i.e.,days,hours,minutes,seconds, ...)template: a file in thestring.Templateformat for the reply email.
Allowed keys: (none yet)notify: list of additional GitHub user/team names (without the@) to@-mention in the commentunclosed-reminderThis 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 berun
manuallyusing theworkflow_dispatchevent.Its parameters are:active: Boolean determining whether or not the workflow is active. If the
workflow is listed in the configuration andactiveis not explicitly
listed, it is assumed thatactive == true.dry: Boolean determining whether to do a dry run. Defaultfalsecron: crontab entry for when this workflow should be runemail-ticket-only: whether to only comment on issues that appear to have
been created from by theemails-to-issuestask.delay: time delta, any issues still open with the last assignment event
older than this time will trigger a reminder comment.
Parameters match those ofdatetime.timedelta(i.e.,days,hours,minutes,seconds, ...)template: a file in thestring.Templateformat for the reply email.
Allowed keys: (none yet)notify: list of additional GitHub user/team names (without the@) to@-mention in the commentassignment-to-gmailThis workflow is triggered immediately when an issue is assigned.Its parameters are:active: Boolean determining whether or not the workflow is active. If the
workflow is listed in the configuration andactiveis not explicitly
listed, it is assumed thatactive == true.dry: Boolean determining whether to do a dry run. DefaultfalseBuild-time vs. run-time configurationSome parameters are used during theticgithub.buildprocess 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 theticgithub.buildprocess. If unsure, rerunningticgithub.buildwill never cause problems, and
might update your workflows for new changes.Most parameters are run-time parameters. The exceptions are:Changes to the name of asecret(inconfig) will always be a build-time
parameter.For scheduled workflows, changes to thecronschedule will always be a
build-time parameter."Installation" / UsageOnce you have created your.ticgithub.ymlfile, you can useticgithubto
create the GHA workflows based on your configuration. On your local machine, in
a clone of your issues repository, installticgithubinto the current
environment:python-mpipinstallticgithubFrom the root directory of your clone of the issues repository, run the command:python-mticgithub.buildThis will create the relevant workflows. Ensure that they are added in a git
commit and push up to your default branch, and you'll haveticgithubup and
running!Running tasks locallyYou can run any of the built-in tasks locally as well. To do this, use, e.g.,python-mticgithub.tasks.emails_to_issuesYou 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-mticgithub.tasks.emails_to_issuesYou can select choose a dry run by passing--dry. You can select a specific
configuration file (other than./.ticgithub.yml) with--configor-c.Theassignment-to-gmailtask takes an additional parameter for the issue
number, e.g,python-mticgithub.tasks.assignment_to_gmail--dry99Customizing the build processThe build process can be further customized based on a build config YAML file.
The default build config is atticgithub/data/build_config.yml.
This allows customization of the files generated by thebuildcommand. There
are two categories of customization: customization ofticgithubitself, and
customization of the individual workflows, under thebuildersheading.Under theticgithubheading:install: the command to run to install ticgithubsuffix: a suffix (to distinguish multiple copies of the same workflow)force-dry: require all commands to run with the--dryflaginstall-path: path to install the GitHub Actions WorkflowsThebuildersheading contains a list where each item is a workflow. For each
workflow, the following keys should be included:config-name: workflow name as used in configurationrun-command: the command to run for this workflowtemplate: the template file to use for this workflow; default is to first
check if the provided value is a path that exists and if not, to check inticgithub/data/workflows/build-params: build-time parameters from the main config for this workflow.
These are key-value pairs with the name of the parameter in the config file
as the key and the substitution variable from the template file (without the
initial$) as the value.