How to automatically manage contributions to open-source projects 🏷️
Tags: tutorial, github, hacktoberfest, opensource
Published: 2021-11-26 08:05:18

October is an exciting month, with people across the world looking forward to Halloween or Oktoberfest. But for me, I'm most excited about [**Hacktoberfest**](https://hacktoberfest.digitalocean.com/)–the month-long celebration of open-source projects. DigitalOcean has been organizing this event for the past eight years with the goal of encouraging the global tech community to support open-source projects.

Hacktoberfest provides a great opportunity on one side for individual developers to apply their skills on real-world projects, and on the other side for organizations to extend their projects with the help of contributors.

However, the popularity of Hacktoberfest also creates spam, unnecessary pull requests, and loads of comments on GitHub issues, which can become overwhelming for the project owners and maintainers.

Our solution to this problem? **Automation**! In this tutorial, you will learn how to create a no-code workflow that automatically assigns an open GitHub issue to a contributor interested in working on it.


#### Table of contents
[Prerequisites for building the workflow](#prerequisites-for-building-the-workflow)  
[Workflow for assigning GitHub issues to contributors](#workflow-for-assigning-github-issues-to-contributors)
&nbsp; &nbsp; [1. Trigger the workflow on GitHub events](#1-trigger-the-workflow-on-github-events) 
&nbsp; &nbsp; [2. Route the workflow on specific events](#2-route-the-workflow-on-specific-events) 
&nbsp; &nbsp; [3. Handle new GitHub issues](#3-handle-new-github-issues) 
&nbsp; &nbsp; [4. Assign the issue](#4-assign-the-issue)
&nbsp; &nbsp; [5. Handle new comments on GitHub issues](#5-handle-new-comments-on-github-issues) 
&nbsp; &nbsp; [6. Check if the issue is already assigned](#6-check-if-the-issue-is-already-assigned)
&nbsp; &nbsp; [7. Assign an issue to a contributor](#7-assign-an-issue-to-a-contributor) 
&nbsp; &nbsp; [8. Add a comment to the issue](#8-add-a-comment-to-the-issue)
[What's next?](#whats-next)

<figure><img src="https://lh3.googleusercontent.com/88uNfhZL9pgwWQbszoOlkwzPNWmMkW9pRJRCYYjzQyAzyyChi05EMW92UJHiQYOC-yWyc-cS882JRmgSZir7Q7qyv-rAC_Mg5qOHBEqM3deTt6w8CEZQPAJzXAAFnNA4yolG0tUD=s1600" alt="Workflow for assigning GitHub issues to contributors" style="width:100%"><figcaption align = "center"><i>Workflow for assigning GitHub issues to contributors</i></figcaption></figure>


## Prerequisites for building the workflow

-   **n8n**: Sign up for [n8n.cloud](https://www.n8n.cloud/) to quickly get started or use n8n on your own servers. Refer to the [installation](https://docs.n8n.io/getting-started/installation/) guide to learn more.
-   **GitHub account**: To connect the workflow with your GitHub account, follow the steps mentioned in the [documentation](https://docs.n8n.io/credentials/github).

## Workflow for assigning GitHub issues to contributors

The general idea of [this workflow](https://n8n.io/workflows/1274) is to assign an issue to the contributor who is interested in working on it. There are four scenarios that you need to consider:

1.  A contributor creates an issue and wants to work on it.
2.  A contributor creates a new issue and doesn't want to work on it.
3.  A contributor is interested in working on an issue reported by another contributor and no one got assigned to it.
4.  A contributor is interested in working on an issue opened by another contributor, but someone else has already been assigned to it.

In popular open-source projects, you usually meet all these scenarios. If you're a project maintainer, you know it can become difficult to manage the contributions efficiently, especially during events like Hacktoberfest.

The visual builder that n8n provides helps you classify and handle issues automatically. Let's dive into it!

### 1\. Trigger the workflow on GitHub events

The workflow should run every time someone opens a  new issue or comments on an issue. For this, add the GitHub Trigger node and configure the following parameters:

-   ***Authentication:*** If you're using n8n.cloud, I suggest you select the OAuth2 authentication method. This option allows you to connect the node with your GitHub account without the need to create credentials. Otherwise, you can learn how to create the credentials from our [documentation](https://docs.n8n.io/credentials/github).
-   ***Repository Owner:*** Enter your GitHub username.
-   ***Repository Name:*** Enter the name of your repository.
-   ***Events:*** Select `issue_comment` and `issues` from the dropdown menu.

<figure><img src="https://lh6.googleusercontent.com/1V_dcj27abNeaRXwpMZ064kBW0MP8kuIiAiFhIb1qMCy-eaR7B2Zes35bKOAZ4VNuOd2NvwyHrqLjgkP5cFS2snGGWmRIM71OiM2Cn5o7qrpnnt-gmLnilgyT80fO6JVrtobm1SK=s1600" alt="Configuration of GitHub Trigger node" style="width:100%"><figcaption align = "center"><i>Configuration of GitHub Trigger node</i></figcaption></figure>

Now the workflow will run when a new issue gets created, closed, or edited, or when a comment gets posted, removed, or edited.

**Note**: If you want to use this workflow for a repository that belongs to an organization, you will have to use the Webhook Trigger node. Refer to the [GitHub documentation](https://docs.github.com/en/developers/webhooks-and-events/webhooks/creating-webhooks#setting-up-a-webhook) to learn to add webhooks to your repository.

### 2\. Route the workflow on specific events

The workflow should continue only when a new issue gets created or a new comment gets posted. To identify these events, add a Switch node and set the following parameters:

-   ***Data Type:*** String
-   ***Value 1:*** Use the expression `{{$json["body"]["action"]}}`

Click on the ***Add Routing Rules*** button. For this workflow, you need two different routes, one to handle each event mentioned above.

The first routing rule handles the scenario where a new issue gets created. For this, configure the following parameters:

-   ***Operation:*** Equal
-   ***Value 2:*** opened
-   ***Output:*** 0

The second routing rule will navigate the data to output 1 of the Switch node when a new comment gets posted on an issue. For this, use the following values:

-   ***Operation:*** Equal
-   ***Value 2:*** created
-   ***Output:*** 1

<figure><img src="https://lh4.googleusercontent.com/gJ-QoHkUjrtSUQjkFzHwrQZioJbUI3Q1PPomjsT7gceWT2sEM8zGRqHnXaP53IbhquqfCLpWk6lpseyFsjBllhA-ojgv1rwwCDNhkk4vcc_IRqPZ-9hogtAYGk-1NmHnkSQakV_U=s1600" alt="Configuration of Switch node" style="width:100%"><figcaption align = "center"><i>Configuration of Switch node</i></figcaption></figure>

### 3\. Handle new GitHub issues

Contributors who open a new issue may or may not want to contribute to it. To make sure that you assign the contributor only if they're interested in working on it, add an IF node connected to the output 0 of the Switch node.

Configure the IF node as follow:

-   ***Value 1:*** Add the expression `{{$json["body"]["issue"]["body"]}}` in the Expression Editor.
-   ***Operation:*** Regex
-   ***Regex:*** /[a,A]ssign[\w*\s*]*me/gm

The above condition checks if the user wants you to assign them the issue or not.

The workflow should also check if the issue has already been assigned to a contributor or not. For this, add another condition in the IF node. This condition should be of the type Number. Set the following parameters for this condition:

-   ***Value 1:*** Use the expression `{{$json["body"]["issue"]["assignees"].length}}`
-   ***Operation:*** Equal
-   ***Value 2:*** 0

<figure><img src="https://lh6.googleusercontent.com/gMLzYulOUY_QY67YusMtV3Ug5lIwNwjuS_46PnmWLsVWbzR9hiczTUMbaq0xDyGAFVO9RaWJLxUNgRC5ZYdI01TNrKErRDm0a7Sr-nC-E-RPYopBuaultdx5-zSDga7XOcXxb2wD=s1600" alt="Configuration of IF node for new GitHub issues" style="width:100%"><figcaption align = "center"><i>Configuration of IF node for new GitHub issues</i></figcaption></figure>

### 4\. Assign the issue

The next step is assigning the issue to the interested contributor and label the issue as `assigned`. To do this, connect a GitHub node to the true output of the IF node and

Configure the parameters of the node as follows:

-   ***Authentication:*** Use the authentication that you used in the GitHub Trigger node
-   ***Resource:*** Issue
-   ***Operation***: Edit
-   ***Repository Owner:*** Enter your GitHub username or use the following expression: `{{$node["Switch"].json["body"]["repository"]["owner"]["login"]}}`
-   ***Repository Name:*** Enter the name of the repository you previously used, or use the following expression: `{{$node["Switch"].json["body"]["repository"]["name"]}}`
-   ***Issue Number:*** Use the expression `{{ $json["body"]["issue"]["number"] }}`

Click on ***Choose Option To Add***, and select *Labels*. Similarly, add the *Assignees* option. Configure these parameters as follow:

-   *Label:* Enter `assigned` or any other label you want to add to the issue.
-   *Assignees:* Enter the following expression: `{{$json.body.issue["user"]["login"]}}`

<figure><img src="https://lh6.googleusercontent.com/bx_vDtHWhHYUeFfQnZLvMU9i2JLkphGcY7nY-KpXe_CutPFr8kfn5Jbki0XZf_T6z1EhXOlxC8ptTIhPdVB-CzOjTbQeFDHSaTnSsElEbhMzB4oTaquXRGuPBTfW76ElctlZ2_Hj=s1600" alt="Configuration of GitHub node for issue assignment" style="width:100%"><figcaption align = "center"><i>Configuration of GitHub node for issue assignment</i></figcaption></figure>

### 5\. Handle new comments on GitHub issues

Your workflow currently handles the following situations:

1.  Assigning the issue to the contributor who opened the issue if the contributor is interested in working on it
2.  Stopping the workflow if the contributor who opened the issue is not interested in working on it.

You now have to design the workflow that handles the other two scenarios. For this, add an IF node connected to output 1 of the Switch node. This node will check if the contributor is interested in working on the issue. Set the following parameters for the IF node:

-   ***Value 1:*** Use the expression `{{$json["body"]["comment"]["body"]}}`
-   ***Operation:*** Regex
-   ***Regex:*** `/[a,A]ssign[\w*\s*]*me/gm`

<figure><img src="https://lh6.googleusercontent.com/UO42hKRGCuOaa2UJJzBHkvDdec-kkGlkC6BG0SUM4E5ApReED_UP_1yVRQ1WBHTfhIPmpg6kcWjKVcB6Yg_aWBfGIEPrtO_onM8HpOPqkHd2sAFZ6tbqrmv_m_JwzI7eQi-7cDSQ=s1600" alt="Configuration of IF node for interested contributors" style="width:100%"><figcaption align = "center"><i>Configuration of IF node for interested contributors</i></figcaption></figure>

### 6\. Check if the issue is already assigned

If a contributor is interested in working on an issue, the workflow should assign them to the issue, but it should also check if someone has previously been assigned to the issue or not. To check this, connect an IF node to the true output of the previous IF node. Set the IF node as follow:

-   ***Value 1:*** Enter the expression `{{$json["body"]["issue"]["assignees"].length}}`
-   ***Operation:*** Equal
-   ***Value 2:*** 0

If no one is assigned to the issue, this node returns true, otherwise false.

<figure><img src="https://lh6.googleusercontent.com/XBawrwEP-EgWXjv4j2NDFUbfsmNVZmNYfvc0VuzODxxs_dBJ_G-vUrBUFcgXWXjn6fqFAkdTaNnY4jn5DebNYwHQ9kyrywH5on44IYIJppwiRm8-ZlApiFUTODXcI2VLaqBpzaP4=s1600" alt="Configuration of IF node for assigned issues" style="width:100%"><figcaption align = "center"><i>Configuration of IF node for assigned issues</i></figcaption></figure>

### 7\. Assign an issue to a contributor

To assign available issues to an interested contributor, connect a GitHub node to the true branch of the previous IF node.

Configure the parameters similarly to the previous GitHub node. In the ***Assignees*** fields, use the expression `{{$json["body"]["comment"]["user"]["login"]}}`. The rest of the parameters should stay the same.

### 8\. Add a comment to the issue

If the issue has already been assigned to a contributor, you should the interested contributor know about it. For this, connect a new GitHub node to the false branch of the IF node. This node will add a comment to the issue.

Set the node parameters as follows:

-   ***Authentication:*** Similar to the previous GitHub node
-   ***Resource:*** Issue
-   ***Operation:*** Create Comment
-   ***Repository Owner***, ***Repository Name***, ***Issue Number:*** Similar to the previous GitHub node
-   ***Body:*** Enter the comment body in this field.

<figure><img src="https://lh3.googleusercontent.com/Xw_WTysQ2JqGR6IepryBP9OM8oLBe7XDEzrPXGclgGYchpd38frV1xoKtxGEMHsZQVXGsPBHeDKjp_n_pF0U8FMDFJK9ddRH4zDio3qHeUObSxTk8cFri2WolUHxZXUXVxEdn82T=s1600" alt="Configuration of GitHub node for commenting on issues" style="width:100%"><figcaption align = "center"><i>Configuration of GitHub node for commenting on issues</i></figcaption></figure>

This is the last node in the workflow. Now you only need to activate the workflow by clicking on the toggle in the top right corner of the Editor UI. The active workflow will run automatically in production.

## What's next?

In this article, you learned to create a no-code workflow that automatically assigns GitHub issues to interested contributors. This kind of automation will help you and our organization maintain your open-source projects–just in time for Hacktoberfest!

Here's what you can do next:

-   **Build more workflows:** There are many other possible automation workflows that could improve your work as a project maintainer and the experience for your contributors. For example, you can build a workflow that checks the progress on an assigned issue to  see if the contributor needs help.
-   **Contribute to n8n:** You can work on [open issues](https://github.com/n8n-io/n8n/issues), [create nodes](https://docs.n8n.io/nodes/creating-nodes/create-node.html#prerequisites), [improve our docs](https://github.com/n8n-io/n8n-docs/blob/master/CONTRIBUTING.md), or [write a blog post](https://docs.n8n.io/reference/contributing.html#write-a-blogpost-%E2%9C%8D%EF%B8%8F).
-   **Read more tutorials:** Learn how to build workflows for other automation use cases, for example a no-code [CI/CD pipeline with GitHub and TravisCI](https://n8n.io/blog/how-to-set-up-a-ci-cd-pipeline-with-no-code/).

I'd like to know how you are using automation to manage your open-source projects! Feel free to message me on [Twitter](https://twitter.com/harshil1712) or discuss in the [community forum](https://community.n8n.io/c/docs-and-tutorials/6) 🧡 And if you want to get the latest content on automation, [subscribe to our newsletter](https://n8n.io/blog/#subscribe) 💌

> This [post](https://n8n.io/blog/automation-for-maintainers-of-open-source-projects/) originally appeared on the n8n.io [blog](https://n8n.io/blog).