Skip to content

Instantly share code, notes, and snippets.

@tadeaspetak
Created July 1, 2022 10:21
Show Gist options
  • Save tadeaspetak/d3502281eb6fd934a6d24ebace3a08a4 to your computer and use it in GitHub Desktop.
Save tadeaspetak/d3502281eb6fd934a6d24ebace3a08a4 to your computer and use it in GitHub Desktop.
Extract asana tasks from PRs between two tags.
import { execSync } from "child_process";
import fetch from "node-fetch";
const token = "YOUR_ACCESS_TOKEN";
const project = "~/dev/deedmob/code/.git";
const prev = "release-20220613.17-48-26";
const next = "release-20220629.18-19-06";
const repo = "DeedMob/deedmob";
(async () => {
// get the PRs (their numbers, actually)
const pulls = execSync(
`git --git-dir ${project} log ${prev}..${next} --reverse --oneline --grep='#' | sed 's/.*(#\\(.*\\))/\\1/'`
)
.toString("utf-8")
.split("\n");
const tasks: string[] = [];
for (const pull of pulls) {
// fetch the `body` of the current PR
const { body } = (await (
await fetch(`https://api.github.com/repos/${repo}/pulls/${pull}`, {
headers: { Authorization: `token ${token}` },
})
).json()) as { body: string | undefined };
// extract all Asana tasks in the description
const matches = Array.from(
body?.matchAll(/(https\:\/\/app\.asana\.com\/.*)/g) ?? []
);
matches.forEach((m) => tasks.push(m[0]));
// wait a little; no idea what the limit for github API is 🤷‍♀️
await new Promise((r) => setTimeout(r, 1000));
}
console.log(tasks);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment