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

Script to add repetitive issues to multiple repos #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
107 changes: 107 additions & 0 deletions scripts/github/github-create-issues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import "dotenv/config";
import { Octokit } from "@octokit/core";

const octokit = new Octokit({
auth: process.env["GH_TOKEN"], // Your GitHub token from environment variable
});

const owner = process.env["GH_OWNER"]; // Owner of the repository from environment variable

const projectId = "PVT_kwDOBaHX684AX9Bo"; // SDK Development

const repos = [
{ repo: "tbdex-rs", labels: ["cicd"] },
{ repo: "tbdex-js", labels: ["cicd"] },
{ repo: "tbdex-kt", labels: ["cicd"] },
{ repo: "web5-kt", labels: ["cicd"] },
{ repo: "web5-js", labels: ["cicd"] },
{ repo: "web5-rs", labels: ["cicd"] },
];

const issueTitle = "Setup artifacts publishing";

const issueBody = `
We need to have an easy automated workflow to publish artifacts to the corresponding sdk registry (npm, maven, crates etc.), and also publish to the internal Artifactory registry too
`;

async function createIssue(repoName, issueTitle, issueBody, labels) {
try {
console.info(`Creating issue in ${repoName}...`)
const issueResponse = await octokit.request(
"POST /repos/{owner}/{repo}/issues",
{
owner,
repo: repoName,
title: issueTitle,
body: issueBody,
labels,
}
);
console.info(`Issue created in ${repoName}: ${issueResponse.data.html_url}`);

await addIssueToProject(issueResponse.data.node_id);
} catch (error) {
console.error(
`Error creating and associating issue in ${repoName}: ${error.message}`
);
}
}

async function addIssueToProject(issueId) {
try {
const mutation = `
mutation ($projectId: ID!, $contentId: ID!) {
addProjectV2ItemById(input: {projectId: $projectId, contentId: $contentId}) {
item {
id
}
}
}
`;
await octokit.graphql(mutation, {
projectId,
contentId: issueId,
});
console.info(`Issue added to project: ${issueId}`);
} catch (error) {
console.error(`Error adding issue to project: ${error.message}`);
}
}

async function createIssues() {
for (const repo of repos) {
await createIssue(repo.repo, issueTitle, issueBody, repo.labels);
}
}

/**
* Used to list all projects ids,so we can update the script
*/
async function listOrgProjects() {
const query = `
query ($orgName: String!) {
organization(login: $orgName) {
projectsV2(first: 100) {
nodes {
id
title
url
}
}
}
}
`;

try {
const response = await octokit.graphql(query, { orgName: owner });
const projects = response.organization.projectsV2.nodes;
projects.forEach(project => {
console.info(`${project.id} - Project Title: ${project.title}, URL: ${project.url}`);
});
} catch (error) {
console.error(`Error fetching projects: ${error.message}`);
}
}

createIssues().catch(console.error);
// listOrgProjects().catch(console.error);
3 changes: 2 additions & 1 deletion scripts/github/github-create-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const labelsToCreate = [
{ "name": "tbdex-orderstatus", "color": "D68910", "description": "tbDEX Order-Status Message" },
{ "name": "tbdex-close", "color": "34495E", "description": "tbDEX Close Message" },
{ "name": "tbdex-server", "color": "3498DB", "description": "HTTP server for tbDEX PFIs " },
{ "name": "tbdex-client", "color": "E74C3C", "description": "HTTP client for tbDEX wallets" }
{ "name": "tbdex-client", "color": "E74C3C", "description": "HTTP client for tbDEX wallets" },
{ "name": "cicd", "color": "94D114", "description": "CI/CD and Automation" },
];

async function fetchExistingLabels() {
Expand Down
Loading