GitHub Action to Attach Commits and Pull Requests to Trello Cards
Tags: github, trello, githubactions, projectmanagement
Published: 2021-04-27 04:28:30

This [GitHub Action](https://github.com/marketplace/actions/github-commit-to-trello-card) lets you easily attach GitHub commits and pull requests to a Trello card simply by including the card number in your git commit message.

---

GitHub Issues is such a [great tool for software development teams](https://dalezak.medium.com/github-pro-tips-for-your-development-team-9fe0f0a48afb). However if the rest of your company is already using Trello, then you are faced with the decision whether to stick with Trello or switch to GitHub Issues.

The upside of sticking with Trello is that it’s already familiar for non-developers so it’s easy for other team members to submit bugs or feature requests. The downside of GitHub is the development team often works in a silo plus it adds another tool others need to become familiar with.

So for our team I decided to stick with Trello, however quickly noticed the disconnect between commits and Trello cards.

There are some GitHub Action out there that can mirror GitHub Issues to Trello Cards, however none really did want I wanted. So I ended up writing my own GitHub Action called [GitHub-Commit-To-Trello-Card](https://github.com/marketplace/actions/github-commit-to-trello-card).

[https://github.com/marketplace/actions/github-commit-to-trello-card](https://github.com/marketplace/actions/github-commit-to-trello-card)

---

Here’s a sample of what the GitHub Action looks like.
```yml
name: GitHub Commit To Trello Comment

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - uses: dalezak/github-commit-to-trello-card@main
        with:
          trello-api-key: ${{ secrets.TRELLO_KEY }}
          trello-auth-token: ${{ secrets.TRELLO_TOKEN }}
          trello-board-id: ${{ secrets.TRELLO_BOARD }}
          trello-card-action: "Attachment"
          trello-list-name-commit: "Doing"
          trello-list-name-pr-open: "Reviewing"
          trello-list-name-pr-closed: "Testing"
```

And these are what each of the action variables are.

- **trello-api-key** — Trello API key, visit https://trello.com/app-key for key
- **trello-auth-token** — Trello auth token, visit https://trello.com/app-key then click generate a token
- **trello-board-id** — Trello board ID, visit a board then append .json to url to find id
- **trello-card-action** — Trello card action, either “Comment” or “Attachment”
- **trello-list-name-commit** — Trello list name for new commit, for example “Doing”, “In Progress”, etc
- **trello-list-name-pr-open** — Trello list name for open pull request, for example “Reviewing”, “In Review”, etc
- **trello-list-name-pr-closed** — Trello list name for closed pull request, for example “Testing”, “Done”, etc

Now to use the action simply include the card number in the git commit message.

```
git add .
git commit -m "Added initial login form for #751"
git push
```

_And voila!_ The commit message is magically attached to Trello card #751.

![trello-card](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dq5fntpew7bo4ncmpjpj.png)
  
I also setup the action to automatically move cards between lists. For example, when a pull request is opened it can move a card to _“Reviewing”_, _“In Review”_, etc, and when the pull request is closed it can move the card to _“Testing”_, _“Done”_, etc according to the _trello-list-name-pr-open_ and _trello-list-name-pr-closed_ variables. _Enjoy!_