Skip to content

Commit

Permalink
feat: optional categories
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcoindev committed Nov 6, 2023
1 parent 037383f commit 96b4a3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 16 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

import dotenv from 'dotenv';
import { Octokit } from 'octokit';
import * as projects from './projects.json';
import _projects from './projects.json';

interface Projects{
urls: string[];
category?: { projectUrl: string}
}

const projects = _projects as Projects;

// init env variables
dotenv.config();
Expand Down Expand Up @@ -84,7 +91,7 @@ async function main() {
// prepare for issue updating
const isDevpoolUnavailableLabel = devpoolIssue.labels?.some((label) => label.name === LABELS.UNAVAILABLE);
const devpoolIssueLabelsStringified = devpoolIssue.labels.map(label => label.name).sort().toString();
const projectIssueLabelsStringified = getDevpoolIssueLabels(projectIssue).sort().toString();
const projectIssueLabelsStringified = getDevpoolIssueLabels(projectIssue, projectUrl).sort().toString();
// Update devpool issue if any of the following has been updated:
// - issue title
// - issue state (open/closed)
Expand All @@ -105,7 +112,7 @@ async function main() {
title: projectIssue.title,
body: projectIssue.html_url,
state: projectIssue.state,
labels: getDevpoolIssueLabels(projectIssue),
labels: getDevpoolIssueLabels(projectIssue, projectUrl),
});
console.log(`Updated: ${devpoolIssue.html_url} (${projectIssue.html_url})`);
} else {
Expand All @@ -123,7 +130,7 @@ async function main() {
repo: DEVPOOL_REPO_NAME,
title: projectIssue.title,
body: projectIssue.html_url,
labels: getDevpoolIssueLabels(projectIssue),
labels: getDevpoolIssueLabels(projectIssue, projectUrl),
});
console.log(`Created: ${createdIssue.data.html_url} (${projectIssue.html_url})`);
}
Expand Down Expand Up @@ -223,7 +230,8 @@ async function getAllIssues(ownerName: string, repoName: string) {
* @param issue issue object
*/
function getDevpoolIssueLabels(
issue: Issue
issue: Issue,
projectUrl: string
) {
// get owner and repo name from issue's URL because the repo name could be updated
const [ownerName, repoName] = getRepoCredentials(issue.html_url);
Expand All @@ -246,6 +254,9 @@ function getDevpoolIssueLabels(
if (!devpoolIssueLabels.includes(projectIssueLabel.name)) devpoolIssueLabels.push(projectIssueLabel.name);
}

// if project category for the project is defined, add its category label
if (projects.category && projectUrl in projects.category) devpoolIssueLabels.push(projects.category.projectUrl);

return devpoolIssueLabels;
}

Expand Down
6 changes: 5 additions & 1 deletion projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
"https://github.com/ubiquity/telegram-ubiquibot",
"https://github.com/ubiquity/ubiquibot-logging",
"https://github.com/gitcoindev/ubiquibot"
]
],
"category": {
"https://github.com/gitcoindev/ubiquibot": "award winning bot fork",
"https://github.com/ubiquity/ubiquity-dollar": "ubidollar"
}
}

0 comments on commit 96b4a3a

Please sign in to comment.