In this article, I'll show how to use Github's API to create milestones/sprints across multiple repositories.
If a person or organization is using multiple repositories under single project and doing sprint planning through Github Project, it requires creating same milestones (to name sprint) across multiple repositories.
Currently, creating milestones across repos is not supported. But one can search using the milestone across multiple repos to display assigned issues in Github Project. Of course, there are plenty of paid tools that do this and many more things.
At my current organization, we were using Asana to manage sprints and tasks. The recent acquisition of Github by Microsoft gave tones of useful features including the Github Project.
It was more convenient for us to connect sprints & tasks with the code through linked issues, but we are using multiple repositories for different micro-services and creating sprint through milestones in each repo was painful.
I believe many of you who are using multiple repos for a single project facing a similar issue.
Enough talk, let me show code to copy-paste 😂.
// script.js
import { Octokit } from "https://cdn.skypack.dev/@octokit/core";
const token = "YOUR_GITHUB_PERSONAL_ACCESS_TOKEN"
const octokit = new Octokit({ auth: token});
const repos = await octokit.request('GET /user/repos');
const milestones = [{
"title": "Sprint 1",
"description": "June 1 to June 7"
"due_on": "2021-06-01T00:00:00Z"
}, {
"title": "Sprint 2",
"description": "June 7 to June 14"
"due_on": "2021-06-07T00:00:00Z"
}];
for (let r=0; r < repos.length; r++) {
let repo = repos[r];
for (let m=0; m < milestones.length; m++) {
let milestone = milestones[m];
let payload = {
owner: repo.owner.login,
repo: repo.name,
title: milestone.title,
description: milestone.description,
due_on: milestone.due_on
};
await octokit.request(`POST /repos/{owner}/{repo}/milestones`, payload);
}
}
Follow steps mentioned in the documentation to get access token.
I've built a small web application to achieve this through the user interface. Feel free to use it and modify it as per need.
Top comments (1)
Very insightful. I can use for my personal projects. Great work!