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

Implement handling RFCs #1212

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3cae67f
Update github.ts
xno-miner Jun 17, 2024
60498ef
Update index.ts
xno-miner Jun 17, 2024
c22b1c8
Minor fix
xno-miner Jun 17, 2024
f0e9c3d
Update helpers/github.ts
xno-miner Jun 17, 2024
9258750
Update devpool-issue-handler.test.ts
xno-miner Jun 17, 2024
a6c3c1e
Update devpool-issue-handler.test.ts
xno-miner Jun 17, 2024
d96e69e
Update index.ts
xno-miner Jun 17, 2024
22ebb9c
Update github.ts
xno-miner Jun 17, 2024
fe8c4c6
Minor fix
xno-miner Jun 17, 2024
80ce59b
Minor clean
xno-miner Jun 17, 2024
20d74be
Fix getting repo name
xno-miner Jun 17, 2024
b77c0c0
Moved DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, DEVPOOL_RFC_OWNER_NAME a…
xno-miner Jun 28, 2024
4f3c962
Moved the DEVPOOL_ variables to .env (copy the values from .env.example)
xno-miner Jun 28, 2024
128c5d8
don't tweet rfcs
xno-miner Jun 28, 2024
212502f
don't tweet rfcs
xno-miner Jun 28, 2024
ea31d8a
Moved the DEVPOOL_ variables back from env
xno-miner Jun 29, 2024
a08862c
Improved code readability
xno-miner Jun 29, 2024
4cafbe3
Minor fix
xno-miner Jun 29, 2024
179586e
Further improved readability
xno-miner Jun 29, 2024
5263f17
Minor fix
xno-miner Jun 29, 2024
1a65d43
Create env variables for devpool/RFC
xno-miner Jul 2, 2024
133d263
Merge branch 'development' into development
xno-miner Jul 25, 2024
66f7d63
Create tests for RFCs
xno-miner Jul 26, 2024
7a583ab
Add missing files
xno-miner Jul 26, 2024
ed3bbf0
JSON.parse RFC env
xno-miner Jul 29, 2024
ea374eb
quotes in ymls
xno-miner Aug 1, 2024
5a7f812
Fix env and enable rfc test
xno-miner Aug 1, 2024
6318d84
minor cleanup
xno-miner Aug 1, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/jest-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ env:
TWITTER_API_KEY_SECRET: "<twitter_api_secret>"
TWITTER_ACCESS_TOKEN: "<twitter_access_token>"
TWITTER_ACCESS_TOKEN_SECRET: "<twitter_access_token_secret>"
DEVPOOL_OWNER_NAME: ubiquity
DEVPOOL_REPO_NAME: devpool-directory
RFC: 0

jobs:
testing:
Expand Down
72 changes: 48 additions & 24 deletions helpers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import { writeFile } from "fs/promises";
import twitter from "./twitter";
import { TwitterMap } from "..";

// Usually
export const DEVPOOL_OWNER_NAME = process.env.DEVPOOL_OWNER_NAME;
export const DEVPOOL_REPO_NAME = process.env.DEVPOOL_REPO_NAME;
export const IS_RFC = process.env.RFC == "1";
xno-miner marked this conversation as resolved.
Show resolved Hide resolved

// For rfc-issue-handler.test.ts
// export const DEVPOOL_OWNER_NAME = "ubiquity";
// export const DEVPOOL_REPO_NAME = "devpool-rfc";
// export const IS_RFC = true;

export type GitHubIssue = RestEndpointMethodTypes["issues"]["get"]["response"]["data"];
export type GitHubLabel = RestEndpointMethodTypes["issues"]["listLabelsOnIssue"]["response"]["data"][0];

Expand Down Expand Up @@ -127,12 +137,24 @@ export function getDevpoolIssueLabels(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
const devpoolIssueLabels = [
getIssuePriceLabel(issue), // price
`Partner: ${ownerName}/${repoName}`, // partner
`id: ${issue.node_id}`, // id
];
if (pricing != "Pricing: not set") {
devpoolIssueLabels = [
pricing,
`Partner: ${ownerName}/${repoName}`, // partner
`id: ${issue.node_id}`, // id
];
}
else {
devpoolIssueLabels = [
`Partner: ${ownerName}/${repoName}`, // partner
`id: ${issue.node_id}`, // id
];
}

// if project is already assigned then add the "Unavailable" label
if (issue.assignee?.login) devpoolIssueLabels.push(LABELS.UNAVAILABLE);
Expand Down Expand Up @@ -283,8 +305,8 @@ export async function calculateStatistics(devpoolIssues: GitHubIssue[]) {

devpoolIssues.forEach((issue) => {
if (!issue.repository_url || !issue.html_url) return;
if (!issue.repository_url.includes(process.env.DEVPOOL_REPO_NAME) || !issue.html_url.includes(process.env.DEVPOOL_REPO_NAME)) return;
if ("repo" in issue && issue.repo != process.env.DEVPOOL_REPO_NAME) return;
if (!issue.repository_url.includes(DEVPOOL_REPO_NAME) || !issue.html_url.includes(DEVPOOL_REPO_NAME)) return;
if ("repo" in issue && issue.repo != DEVPOOL_REPO_NAME) return;

const linkedRepoFromBody = issue.body?.match(/https:\/\/github.com\/[^/]+\/[^/]+/);
const linkedRepoFromBodyAlt = issue.body?.match(/https:\/\/www.github.com\/[^/]+\/[^/]+/);
Expand Down Expand Up @@ -326,8 +348,8 @@ export async function calculateStatistics(devpoolIssues: GitHubIssue[]) {

export async function writeTotalRewardsToGithub(statistics: Statistics) {
try {
const owner = process.env.DEVPOOL_OWNER_NAME;
const repo = process.env.DEVPOOL_REPO_NAME;
const owner = DEVPOOL_OWNER_NAME;
const repo = DEVPOOL_REPO_NAME;
const filePath = "total-rewards.json";
const content = JSON.stringify(statistics, null, 2);

Expand Down Expand Up @@ -380,14 +402,14 @@ export async function createDevPoolIssue(projectIssue: GitHubIssue, projectUrl:

// check if the issue is the same type as it should be
const hasPriceLabel = (projectIssue.labels as GitHubLabel[]).some((label) => label.name.includes(LABELS.PRICE));
const hasCorrectPriceLabel = (process.env.RFC && !hasPriceLabel) || (!process.env.RFC && hasPriceLabel)
const hasCorrectPriceLabel = (IS_RFC && !hasPriceLabel) || (!IS_RFC && hasPriceLabel)
if (!hasCorrectPriceLabel) return;

// create a new issue
try {
const createdIssue = await octokit.rest.issues.create({
owner: process.env.DEVPOOL_OWNER_NAME,
repo: process.env.DEVPOOL_REPO_NAME,
owner: DEVPOOL_OWNER_NAME,
repo: DEVPOOL_REPO_NAME,
title: projectIssue.title,
body,
labels: getDevpoolIssueLabels(projectIssue, projectUrl),
Expand All @@ -400,7 +422,7 @@ export async function createDevPoolIssue(projectIssue: GitHubIssue, projectUrl:
}

// post to social media (only if it's not an RFC)
if (!process.env.RFC) {
if (!IS_RFC) {
try {
const socialMediaText = getSocialMediaText(createdIssue.data);
const tweetId = await twitter.postTweet(socialMediaText);
Expand Down Expand Up @@ -466,8 +488,8 @@ async function applyMetaChanges(
if (shouldUpdate) {
try {
await octokit.rest.issues.update({
owner: process.env.DEVPOOL_OWNER_NAME,
repo: process.env.DEVPOOL_REPO_NAME,
owner: DEVPOOL_OWNER_NAME,
repo: DEVPOOL_REPO_NAME,
issue_number: devpoolIssue.number,
title: metaChanges.title ? projectIssue.title : devpoolIssue.title,
body: metaChanges.body && !isFork ? projectIssue.html_url : projectIssue.html_url.replace("https://", "https://www."),
Expand All @@ -484,7 +506,9 @@ async function applyMetaChanges(
}

async function applyStateChanges(projectIssues: GitHubIssue[], projectIssue: GitHubIssue, devpoolIssue: GitHubIssue, hasPriceLabel: boolean) {
const hasCorrectPriceLabel = (process.env.RFC && !hasPriceLabel) || (!process.env.RFC && hasPriceLabel)
const hasCorrectPriceLabel = (IS_RFC && !hasPriceLabel) || (!IS_RFC && hasPriceLabel)

// console.log(hasCorrectPriceLabel)

const stateChanges: StateChanges = {
// missing in the partners
Expand All @@ -495,13 +519,13 @@ async function applyStateChanges(projectIssues: GitHubIssue[], projectIssue: Git
},
// no price labels set and open in the devpool
noPriceLabels_Close: {
cause: (!process.env.RFC) && (!hasCorrectPriceLabel) && devpoolIssue.state === "open",
cause: (!IS_RFC) && (!hasCorrectPriceLabel) && devpoolIssue.state === "open",
effect: "closed",
comment: "Closed (no price labels)",
},
// HAS price labels set and open in the RFC devpool
rfcPriceLabels_Close: {
cause: process.env.RFC && (!hasCorrectPriceLabel) && devpoolIssue.state === "open",
cause: IS_RFC && (!hasCorrectPriceLabel) && devpoolIssue.state === "open",
effect: "closed",
comment: "Closed (has price labels)",
},
Expand Down Expand Up @@ -560,8 +584,8 @@ async function applyStateChanges(projectIssues: GitHubIssue[], projectIssue: Git

try {
await octokit.rest.issues.update({
owner: process.env.DEVPOOL_OWNER_NAME,
repo: process.env.DEVPOOL_REPO_NAME,
owner: DEVPOOL_OWNER_NAME,
repo: DEVPOOL_REPO_NAME,
issue_number: devpoolIssue.number,
state: value.effect,
});
Expand Down Expand Up @@ -597,8 +621,8 @@ async function applyUnavailableLabelToDevpoolIssue(
) {
try {
await octokit.rest.issues.addLabels({
owner: process.env.DEVPOOL_OWNER_NAME,
repo: process.env.DEVPOOL_REPO_NAME,
owner: DEVPOOL_OWNER_NAME,
repo: DEVPOOL_REPO_NAME,
issue_number: devpoolIssue.number,
labels: metaChanges.labels ? labelRemoved.concat(LABELS.UNAVAILABLE) : originals.concat(LABELS.UNAVAILABLE),
});
Expand All @@ -608,8 +632,8 @@ async function applyUnavailableLabelToDevpoolIssue(
} else if (projectIssue.state === "closed" && devpoolIssue.labels.some((label) => (label as GitHubLabel).name === LABELS.UNAVAILABLE)) {
try {
await octokit.rest.issues.removeLabel({
owner: process.env.DEVPOOL_OWNER_NAME,
repo: process.env.DEVPOOL_REPO_NAME,
owner: DEVPOOL_OWNER_NAME,
repo: DEVPOOL_REPO_NAME,
issue_number: devpoolIssue.number,
name: LABELS.UNAVAILABLE,
});
Expand Down
11 changes: 7 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import dotenv from "dotenv";
import {
DEVPOOL_OWNER_NAME,
DEVPOOL_REPO_NAME,
IS_RFC,
getAllIssues,
getIssueByLabel,
getProjectUrls,
Expand Down Expand Up @@ -33,15 +36,15 @@ async function main() {
}

// get devpool issues
const devpoolIssues: GitHubIssue[] = (await getAllIssues(process.env.DEVPOOL_OWNER_NAME, process.env.DEVPOOL_REPO_NAME))
const devpoolIssues: GitHubIssue[] = (await getAllIssues(DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME))

// aggregate projects.urls and opt settings
const projectUrls = await getProjectUrls();

// aggregate all project issues
const allProjectIssues: GitHubIssue[] = [];

const isFork = await checkIfForked(process.env.DEVPOOL_OWNER_NAME);
const isFork = await checkIfForked(DEVPOOL_OWNER_NAME);

// for each project URL
for (const projectUrl of projectUrls) {
Expand Down Expand Up @@ -72,8 +75,8 @@ async function main() {
}

// Calculate total rewards from devpool issues
if (!process.env.RFC) {
const { rewards, tasks } = await calculateStatistics(await getAllIssues(process.env.DEVPOOL_OWNER_NAME, process.env.DEVPOOL_REPO_NAME));
if (IS_RFC) {
const { rewards, tasks } = await calculateStatistics(await getAllIssues(DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME));
const statistics: Statistics = { rewards, tasks };

await writeTotalRewardsToGithub(statistics);
Expand Down