1
0
mirror of https://github.com/spacebarchat/spacebarchat.git synced 2024-09-19 17:01:47 +02:00

push issues org wide to notion board

This commit is contained in:
xnacly 2021-08-09 15:37:02 +02:00
parent e7b4a71837
commit aa84c6afe0
4 changed files with 245 additions and 10 deletions

View File

@ -1,10 +1,13 @@
const fetch = require("node-fetch");
const { Client } = require("@notionhq/client");
class GithubNotionSync {
constructor(config, githubOrg) {
this.github_auth = config.githubAuth;
this.notion_auth = config.notionAuth;
constructor(config, githubOrg, notionDatabase) {
this.githubAuth = config.githubAuth;
this.notionAuth = config.notionAuth;
this.databaseID = notionDatabase;
this.org = githubOrg;
this.notion = new Client({ auth: this.notionAuth });
this.urls = {
base: "https://api.github.com/",
};
@ -17,7 +20,7 @@ class GithubNotionSync {
async getAllIssueUrls() {
let repos = await fetch(`${this.urls.base}orgs/${this.org}/repos`, {
headers: {
Authorization: `token ${this.github_auth}`,
Authorization: `token ${this.githubAuth}`,
"User-Agent": this.org,
},
}).then((r) => r.json());
@ -44,7 +47,7 @@ class GithubNotionSync {
async getAllIssuesPerRepo(repoIssueUrl) {
let issues = await fetch(repoIssueUrl, {
headers: {
Authorization: `token ${this.github_auth}`,
Authorization: `token ${this.githubAuth}`,
"User-Agent": this.org,
},
}).then((r) => r.json());
@ -60,5 +63,84 @@ class GithubNotionSync {
};
});
}
async addItemToDb(issue) {
try {
const response = await this.notion.pages.create({
parent: { database_id: this.databaseID },
properties: {
Name: {
title: [
{
text: {
content: issue.title /*.replace(
/(\[.+\].)/g,
""
),*/,
},
},
],
},
State: {
select: {
name: issue.state,
},
},
// "Type of Issue": {
// select: {
// name:
// issue.title.split("]")[0].replace("[", "") ||
// "none",
// },
// },
Label: {
select: {
name: issue.label || "none",
},
},
Assignee: {
select: {
name: issue.assignee || "none",
},
},
Repo: {
select: {
name: issue.url.match(
/fosscord\/(fosscord-)?([\w.-]+)/
)[2],
},
},
Url: {
url: issue.url,
},
Number: { number: issue.number },
},
children: [
{
object: "block",
type: "paragraph",
paragraph: {
text: [
{
type: "text",
text: {
content: `${
issue.body.length > 1990
? "issue body too long"
: issue.body
}`,
},
},
],
},
},
],
});
console.log(response);
} catch (error) {
console.log(issue);
console.error(error.body);
}
}
}
module.exports = { GithubNotionSync };

View File

@ -1,14 +1,19 @@
const config = require("./config.json");
const config = require("./private.json");
const { GithubNotionSync } = require("./GithubNotionSync");
const sync = new GithubNotionSync(config, "fosscord");
const sync = new GithubNotionSync(
config,
"fosscord",
"2c7fe9e73f9842d3bab3a4912dedd091"
);
(async () => {
const repos = await sync.getAllIssueUrls();
const issues = [];
let issues = 0;
for (repo of repos) {
for (issue of await sync.getAllIssuesPerRepo(repo)) {
issues.push(issue);
await sync.addItemToDb(issue);
issues++;
}
}
console.log(issues);
console.log(`synced ${issues}`);
})();

View File

@ -8,9 +8,92 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@notionhq/client": "^0.2.4",
"node-fetch": "^2.6.1"
}
},
"node_modules/@notionhq/client": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/@notionhq/client/-/client-0.2.4.tgz",
"integrity": "sha512-omokCm0TwRH0DTCkHGCX4V4jEd7XQoMvQ9d7bcLn+mZgnTW5uU50T+vqQudr6p3y3BMeCXROI/u+JmU2RJT/AQ==",
"dependencies": {
"@types/node-fetch": "^2.5.10",
"node-fetch": "^2.6.1"
},
"engines": {
"node": ">=12"
}
},
"node_modules/@types/node": {
"version": "16.4.13",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.13.tgz",
"integrity": "sha512-bLL69sKtd25w7p1nvg9pigE4gtKVpGTPojBFLMkGHXuUgap2sLqQt2qUnqmVCDfzGUL0DRNZP+1prIZJbMeAXg=="
},
"node_modules/@types/node-fetch": {
"version": "2.5.12",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.12.tgz",
"integrity": "sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==",
"dependencies": {
"@types/node": "*",
"form-data": "^3.0.0"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/mime-db": {
"version": "1.49.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz",
"integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.32",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
"integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==",
"dependencies": {
"mime-db": "1.49.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
@ -21,6 +104,70 @@
}
},
"dependencies": {
"@notionhq/client": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/@notionhq/client/-/client-0.2.4.tgz",
"integrity": "sha512-omokCm0TwRH0DTCkHGCX4V4jEd7XQoMvQ9d7bcLn+mZgnTW5uU50T+vqQudr6p3y3BMeCXROI/u+JmU2RJT/AQ==",
"requires": {
"@types/node-fetch": "^2.5.10",
"node-fetch": "^2.6.1"
}
},
"@types/node": {
"version": "16.4.13",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.13.tgz",
"integrity": "sha512-bLL69sKtd25w7p1nvg9pigE4gtKVpGTPojBFLMkGHXuUgap2sLqQt2qUnqmVCDfzGUL0DRNZP+1prIZJbMeAXg=="
},
"@types/node-fetch": {
"version": "2.5.12",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.12.tgz",
"integrity": "sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==",
"requires": {
"@types/node": "*",
"form-data": "^3.0.0"
}
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"requires": {
"delayed-stream": "~1.0.0"
}
},
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
"form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"mime-db": {
"version": "1.49.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz",
"integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA=="
},
"mime-types": {
"version": "2.1.32",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
"integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==",
"requires": {
"mime-db": "1.49.0"
}
},
"node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",

View File

@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@notionhq/client": "^0.2.4",
"node-fetch": "^2.6.1"
}
}