generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of https://github.com/ubiquity/devpool-dir…
…ectory into development
- Loading branch information
Showing
17 changed files
with
220 additions
and
260 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,26 @@ | ||
import { GitHubIssue, GitHubLabel, LABELS, PRICING_NOT_SET, projects } from "./directory"; | ||
import { getIssuePriceLabel } from "./get-issue-price-label"; | ||
import { getRepoCredentials } from "./get-repo-credentials"; | ||
|
||
/** | ||
* Returns array of labels for a devpool issue | ||
* @param issue issue object | ||
* @param projectUrl url of the project | ||
*/ | ||
export function getDirectoryIssueLabelsFromPartnerIssue(partnerIssue: GitHubIssue) { | ||
const buffer: string[] = [`id: ${partnerIssue.node_id}`]; | ||
const pricing = getIssuePriceLabel(partnerIssue); | ||
|
||
export function getDirectoryIssueLabels(issue: GitHubIssue, 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); | ||
|
||
const pricing = getIssuePriceLabel(issue); | ||
|
||
let devpoolIssueLabels: string[]; | ||
|
||
// default labels | ||
if (pricing != PRICING_NOT_SET) { | ||
devpoolIssueLabels = [ | ||
pricing, | ||
`Partner: ${ownerName}/${repoName}`, | ||
`id: ${issue.node_id}`, // id | ||
]; | ||
} else { | ||
devpoolIssueLabels = [ | ||
`Partner: ${ownerName}/${repoName}`, | ||
`id: ${issue.node_id}`, // id | ||
]; | ||
buffer.push(pricing); | ||
} | ||
|
||
// if project is already assigned then add the "Unavailable" label | ||
if (issue.assignee?.login) devpoolIssueLabels.push(LABELS.UNAVAILABLE); | ||
|
||
const labels = issue.labels as GitHubLabel[]; | ||
|
||
// add all missing labels that exist in a project's issue and don't exist in devpool issue | ||
for (const projectIssueLabel of labels) { | ||
// skip the "Price" label in order to not accidentally generate a permit | ||
if (projectIssueLabel.name.includes("Price")) continue; | ||
// if project issue label does not exist in devpool issue then add it | ||
if (!devpoolIssueLabels.includes(projectIssueLabel.name)) devpoolIssueLabels.push(projectIssueLabel.name); | ||
if (partnerIssue.assignees && partnerIssue.assignees.length > 0) { | ||
buffer.push(LABELS.UNAVAILABLE); | ||
} | ||
|
||
// 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; | ||
const partnerIssueLabels = partnerIssue.labels as GitHubLabel[]; | ||
// add all missing labels that exist in a project's issue and don't exist in Directory issue | ||
for (const label of partnerIssueLabels) { | ||
// add all missing labels that exist in a project's issue and don't exist in Directory issue | ||
if (label.name.includes("Price")) continue; // skip the "Price" label in order to not accidentally generate a permit | ||
if (!buffer.includes(label.name)) buffer.push(label.name); // if project issue label does not exist in Directory issue then add it | ||
} | ||
if (projects.category && partnerIssue.html_url in projects.category) buffer.push(projects.category[partnerIssue.html_url]); // if project category for the project is defined, add its category label | ||
return buffer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubLabel, octokit } from "./directory"; | ||
|
||
// Function to check if a label exists | ||
export async function ensureLabelExists(labelName: string, labelColor: string, labelDescription: string): Promise<void> { | ||
try { | ||
// Fetch all labels in the repository | ||
let labels = [] as GitHubLabel[]; | ||
let page = 1; | ||
let hasNextPage = true; | ||
|
||
while (hasNextPage) { | ||
const response = await octokit.rest.issues.listLabelsForRepo({ | ||
owner: DEVPOOL_OWNER_NAME, | ||
repo: DEVPOOL_REPO_NAME, | ||
per_page: 100, | ||
page: page, | ||
}); | ||
|
||
labels = labels.concat(response.data); | ||
|
||
if (response.data.length < 100) { | ||
hasNextPage = false; | ||
} else { | ||
page++; | ||
} | ||
} | ||
|
||
// Check if the label already exists | ||
const isLabelPresent = labels.some((label) => label.name === labelName); | ||
|
||
// If the label does not exist, create it | ||
if (!isLabelPresent) { | ||
await octokit.rest.issues.createLabel({ | ||
owner: DEVPOOL_OWNER_NAME, | ||
repo: DEVPOOL_REPO_NAME, | ||
name: labelName, | ||
color: "ededed", | ||
description: labelDescription, | ||
}); | ||
console.log(`Created label "${labelName}"`); | ||
} | ||
} catch (error) { | ||
console.error(`Error ensuring label "${labelName}" exists:`, error); | ||
throw error; // Rethrow the error after logging | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, octokit } from "./directory"; | ||
import { checkIfForked } from "./check-if-forked"; | ||
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, octokit } from "./directory"; | ||
import { MetadataInterface } from "./sync-issue-meta-data"; | ||
|
||
export async function setMetaChanges({ | ||
metaChanges, | ||
remoteFullIssue, | ||
directoryIssue, | ||
labelRemoved, | ||
originalLabels, | ||
}: { | ||
metaChanges: { title: boolean; body: boolean; labels: boolean }; | ||
remoteFullIssue: GitHubIssue; | ||
directoryIssue: GitHubIssue; | ||
labelRemoved: string[]; | ||
originalLabels: string[]; | ||
}) { | ||
export async function setMetaChanges({ metaChanges, partnerIssue, directoryIssue, labelRemoved, originalLabels }: MetadataInterface) { | ||
const shouldUpdate = metaChanges.title || metaChanges.body || metaChanges.labels; | ||
|
||
if (shouldUpdate) { | ||
let newBody = remoteFullIssue.body; | ||
|
||
newBody = directoryIssue.html_url; | ||
let directoryIssueBody = partnerIssue.html_url; | ||
const isFork = await checkIfForked(); | ||
if (isFork) { | ||
directoryIssueBody = partnerIssue.html_url.replace("https://github.com", "https://www.github.com"); | ||
} | ||
|
||
try { | ||
await octokit.rest.issues.update({ | ||
owner: DEVPOOL_OWNER_NAME, | ||
repo: DEVPOOL_REPO_NAME, | ||
issue_number: remoteFullIssue.number, | ||
title: metaChanges.title ? directoryIssue.title : remoteFullIssue.title, | ||
body: newBody, | ||
issue_number: directoryIssue.number, | ||
title: metaChanges.title ? directoryIssue.title : directoryIssue.title, | ||
body: directoryIssueBody, | ||
labels: metaChanges.labels ? labelRemoved : originalLabels, | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
|
||
console.log(`Updated metadata: ${remoteFullIssue.html_url} - (${directoryIssue.html_url})`, metaChanges); | ||
console.log(`Updated metadata for issue:`, { | ||
partnerIssueUrl: partnerIssue.html_url, | ||
directoryIssueUrl: directoryIssue.html_url, | ||
changes: metaChanges, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.