Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: no backlinks #1062

Merged
merged 6 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions helpers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ export async function forceCloseMissingIssues(devpoolIssues: GitHubIssue[], proj
}
}

/**
* Stops forks from spamming real Ubiquity issues with links to their forks
* @returns true if the authenticated user is Ubiquity
*/
export async function checkIfForked() {
try {
const {
data: { id },
} = await octokit.users.getAuthenticated();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little bit concerned that it will authenticate as the bot itself instead of the organization. But I asked ChatGPT and it said that this implementation should be fine.

https://chat.openai.com/share/47cc89cc-cd67-4f68-931f-fe6e1b81ba5e

return id && id === 76412717 ? true : false;
} catch (e: unknown) {
console.warn(`Getting authenticated user failed: ${e}`);
return false;
}
}

/**
* Returns all issues in a repo
* @param ownerName owner name
Expand Down
10 changes: 8 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getSocialMediaText,
GitHubIssue,
GitHubLabel,
checkIfForked,
LABELS,
octokit,
} from "./helpers/github";
Expand All @@ -35,6 +36,8 @@ async function main() {
// aggregate all project issues
const allProjectIssues: GitHubIssue[] = [];

const isFork = await checkIfForked();

// for each project URL
for (const projectUrl of projectUrls) {
// get owner and repository names from project URL
Expand All @@ -47,6 +50,8 @@ async function main() {
for (const projectIssue of projectIssues) {
// if issue exists in devpool
const devpoolIssue = getIssueByLabel(devpoolIssues, `id: ${projectIssue.node_id}`);
const body = isFork ? projectIssue.html_url : projectIssue.html_url.replace("https://github.com", "https://www.github.com");

if (devpoolIssue) {
// If project issue doesn't have the "Price" label (i.e. it has been removed) then close
// the devpool issue if it is not already closed, no need to pollute devpool repo with draft issues
Expand Down Expand Up @@ -90,7 +95,7 @@ async function main() {
repo: DEVPOOL_REPO_NAME,
issue_number: devpoolIssue.number,
title: projectIssue.title,
body: projectIssue.html_url,
body,
state: projectIssue.state as "open" | "closed",
labels: getDevpoolIssueLabels(projectIssue, projectUrl),
});
Expand All @@ -104,12 +109,13 @@ async function main() {
if (projectIssue.state === "closed") continue;
// if issue doesn't have the "Price" label then skip it, no need to pollute repo with draft issues
if (!(projectIssue.labels as GitHubLabel[]).some((label) => label.name.includes(LABELS.PRICE))) continue;

// create a new issue
const createdIssue = await octokit.rest.issues.create({
owner: DEVPOOL_OWNER_NAME,
repo: DEVPOOL_REPO_NAME,
title: projectIssue.title,
body: projectIssue.html_url,
body,
labels: getDevpoolIssueLabels(projectIssue, projectUrl),
});
console.log(`Created: ${createdIssue.data.html_url} (${projectIssue.html_url})`);
Expand Down
5 changes: 2 additions & 3 deletions opt.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
"ubiquity/devpool-directory",
"ubiquity/card-issuance",
"ubiquity/research",
"ubiquity/recruiting",
"ubiquity/business-development",
"ubiquity/ubiquibar",
"ubiquity/ubiquibot",
"ubiquity/ubiquibot-telegram",

"ubiquibot/configuration",
"ubiquibot/comment-incentives",
"ubiquibot/production",
"ubiquibot/sandbox",
"ubiquibot/e2e-tests",
"ubiquibot/staging"
]
}
}