Create ways for limiting WIP
Tags: git, automation, jira, scrum
Published: 2020-11-07 23:16:16

## What is WIP limit and why it's important

> WIP limits (work-in-process limits) are fixed constraints, typically implemented on Kanban boards, that help teams actively eliminate waste from their processes. WIP limits enable teams to optimize their workflows for value delivery

Okay but why is it so important?

### Get stuff done 💪

WIP limits enforces the team to focus on a smaller set of tasks which improves the throughput and reduces the frustration of having things "nearly done". The result a feeling of getting things done faster

### Avoid context switching 🤷‍♂️

According to Gloria Mark, Professor of Informatics at the UC – Irvine, "people compensate for interruptions by working faster, but this comes at a price: experiencing more stress, higher frustration, time pressure and effort." 

## How to automate it 🤖

In this article, we will automate the WIP limiting using `Jira REST API`. However the approach and key ideas can be replicated for any project software tracking which contains a REST API

### Jira is your friend 😇

With the following, you can see all Jira issues assigned to you which are `In Progress`

```jsx
assignee = currentUser() AND status = "In Progress" order by created DESC
```

Using `Jira REST API` it would look like this

```jsx
https://{{jiraBaseUrl}}/rest/api/3/search?jql=assignee%20%3D%20currentUser()%20AND%20status%20%3D%20"In%20Progress"%20order%20by%20created%20DESC
```

Using the query above you can easily create reminders for you team to keep the WIP limited

### Slack reminders

From [slack's reminder documentation](https://slack.com/intl/en-es/help/articles/208423427-Set-a-reminder) we can create a reminder using the following command:

`/remind [@someone or #channel] [what] [when]`

In our case, we want to to use the Jira query as the `what` here. 

So for a daily personal WIP limit reminder we would have something like this

```jsx
/remind me to 👋 Limit my WIP at 10am Every weekday
```

**Pro-tip:** Add a link to "Limit my WIP"  using `CMD + Shift + U` and set the Jira URL from the query we've created above

### Git hooks

If you're not using slack or prefer not to leave the terminal for getting these reminders, you can use git hooks. In our case, we will use [post-checkout](https://git-scm.com/docs/githooks#_post_checkout). 

The reason behind the decision of using this hook is that  normally when starting a new task, at some point the developer will create a new branch using `git checkout -b <branch>`  the hook will be triggered right after this command

Using the Jira query above we are able to create the following `post-checkout` git hook

<script src="[https://gist.github.com/horowitz/b1a46587c944935fdf0e6301c8a9f4ae.js](https://gist.github.com/horowitz/b1a46587c944935fdf0e6301c8a9f4ae.js)"></script>

Here we are using 2 env vars

- `JIRA_API_TOKEN` Api token to authenticate in Jira. [More info here](https://confluence.atlassian.com/cloud/api-tokens-938839638.html)
- `WIP_LIMIT` env var to set wip limit

Also this piece of code is using `jq` to retrieve JSON fields

### References

[https://www.ics.uci.edu/~gmark/chi08-mark.pdf](https://www.ics.uci.edu/~gmark/chi08-mark.pdf)

[https://www.atlassian.com/agile/kanban/wip-limits](https://www.atlassian.com/agile/kanban/wip-limits)

[https://www.planview.com/resources/articles/wip-limits/](https://www.planview.com/resources/articles/wip-limits/)