-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Adding initial scripts #1
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,2 +1,22 @@ | ||
# tooling | ||
Tooling used in the project | ||
Tooling used in the project. | ||
|
||
Simple scripts without extra fuss to help with the project. Written with less effort and more focus on the task at hand. | ||
|
||
## Scripts | ||
### `owner/create-label.mjs` - Create Label | ||
Allows you to create a label in all existing repositories in an organization. | ||
|
||
### `triage/subscribe-to-org-repos.js` - Subscribe to Org Repos | ||
Allows you to subscribe to all repositories in an organization. | ||
|
||
## Usage | ||
1. Clone the repository | ||
2. Install the required dependency for the script you want to use | ||
3. Make necessary changes to the script | ||
4. Run the script | ||
|
||
## Note | ||
- Your GitHub token should have the necessary permissions to perform the actions. | ||
|
||
|
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,53 @@ | ||
import { Octokit } from '@octokit/rest'; | ||
|
||
const octokit = new Octokit({ | ||
auth: 'token', // should have repo and admin:org scope | ||
}); | ||
|
||
// Set the organization name, label name, color, and description | ||
const orgName = 'org-name'; | ||
const labelName = 'label-name'; | ||
const labelColor = 'ff0000'; | ||
const labelDescription = 'label-description'; | ||
|
||
async function createLabelInRepo(owner, repo) { | ||
try { | ||
await octokit.issues.createLabel({ | ||
owner, | ||
repo, | ||
name: labelName, | ||
color: labelColor, | ||
description: labelDescription, | ||
}); | ||
console.log(`Label '${labelName}' created in ${repo}`); | ||
} catch (error) { | ||
if (error.status === 422) { | ||
console.log(`Label '${labelName}' already exists in ${repo}`); | ||
} else { | ||
console.error( | ||
`Failed to create label in ${repo}: ${error.message}` | ||
); | ||
} | ||
} | ||
} | ||
|
||
async function createLabelInAllRepos() { | ||
try { | ||
const repos = await octokit.paginate(octokit.repos.listForOrg, { | ||
org: orgName, | ||
}); | ||
|
||
for (const repo of repos) { | ||
await createLabelInRepo(orgName, repo.name); | ||
} | ||
|
||
console.log('Label creation completed.'); | ||
} catch (error) { | ||
console.error( | ||
`Error fetching repositories or creating labels: ${error.message}` | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
createLabelInAllRepos(); |
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,52 @@ | ||
const axios = require('axios'); | ||
|
||
// Replace with your GitHub token and organization name | ||
const GITHUB_TOKEN = 'token'; | ||
const ORGANIZATION_NAME = 'pillarjs'; | ||
|
||
const subscribeToAllRepos = async () => { | ||
try { | ||
const headers = { | ||
'Authorization': `token ${GITHUB_TOKEN}`, | ||
'Accept': 'application/vnd.github.v3+json', | ||
}; | ||
|
||
// Fetch all repositories of the organization | ||
let page = 1; | ||
let repos = []; | ||
|
||
while (true) { | ||
const response = await axios.get(`https://api.github.com/orgs/${ORGANIZATION_NAME}/repos?per_page=100&page=${page}`, { headers }); | ||
|
||
if (response.data.length === 0) { | ||
break; | ||
} | ||
|
||
repos = repos.concat(response.data); | ||
page++; | ||
} | ||
|
||
console.log(`Found ${repos.length} repositories in the organization ${ORGANIZATION_NAME}.`); | ||
|
||
// Subscribe (watch) to each repository | ||
for (const repo of repos) { | ||
const { full_name } = repo; | ||
try { | ||
await axios.put( | ||
`https://api.github.com/repos/${full_name}/subscription`, | ||
{ subscribed: true, ignored: false }, | ||
{ headers } | ||
); | ||
console.log(`Subscribed to ${full_name}`); | ||
} catch (error) { | ||
console.error(`Failed to subscribe to ${full_name}: ${error.message}`); | ||
} | ||
} | ||
|
||
console.log('Finished subscribing to all repositories.'); | ||
} catch (error) { | ||
console.error('Error:', error.message); | ||
} | ||
}; | ||
|
||
subscribeToAllRepos(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be passed as command-line arguments using process.argv
Or simply add the three organizations.