-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ctinnovation/feat/BAC-931/gitstronaut-init
Feat/bac 931/gitstronaut init
- Loading branch information
Showing
15 changed files
with
4,481 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
commonjs: true, | ||
es2021: true | ||
}, | ||
extends: 'standard', | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true | ||
}, | ||
files: [ | ||
'.eslintrc.{js,cjs}' | ||
], | ||
parserOptions: { | ||
sourceType: 'script' | ||
} | ||
} | ||
], | ||
parserOptions: { | ||
ecmaVersion: 'latest' | ||
}, | ||
rules: { | ||
} | ||
} |
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,130 @@ | ||
name: Create new release | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: [closed] | ||
workflow_dispatch: | ||
inputs: | ||
semver: | ||
description: "Semver version" | ||
required: true | ||
default: "minor" | ||
|
||
jobs: | ||
create: | ||
name: Create PR for new release | ||
if: github.event.inputs.semver | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.REPO_ACCESS }} | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.x" | ||
registry-url: https://npm.pkg.github.com/ | ||
scope: "@ctinnovation" | ||
|
||
- name: install dependencies | ||
run: npm install -g @ctinnovation/changelogger | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_GET_TOKEN}} | ||
|
||
- name: setup git config | ||
run: | | ||
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default | ||
git config user.name "GitHub Actions Bot" | ||
git config user.email "<[email protected]>" | ||
- name: update version and changelog | ||
run: | | ||
npm version ${{ github.event.inputs.semver }} --no-git-tag-version | ||
- name: Get new version from package.json | ||
run: | | ||
pkg_version=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') | ||
echo "PACKAGE_VERSION=$pkg_version" >> $GITHUB_ENV | ||
echo $PACKAGE_VERSION | ||
- name: Create pull request | ||
id: pr-create | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ github.token }} | ||
script: | | ||
const res = await github.rest.pulls.create({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
ref: "refs/tags/tagname", | ||
head: "release_${{ env.PACKAGE_VERSION }}", | ||
base: "main", | ||
title: "Release: [v${{ env.PACKAGE_VERSION }}]", | ||
body: `PR created by Github Actions bot in order to release new version **v${{ env.PACKAGE_VERSION }}**.` | ||
}) | ||
return res.data.number; | ||
- name: Request and assign review | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ github.token }} | ||
script: | | ||
await github.rest.pulls.requestReviewers({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: ${{ steps.pr-create.outputs.result }}, | ||
reviewers: ['${{ github.actor }}'] | ||
}); | ||
await github.rest.issues.addAssignees({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: ${{ steps.pr-create.outputs.result }}, | ||
assignees: ['${{ github.actor }}'] | ||
}); | ||
publish: | ||
name: Tagging and publish new release | ||
runs-on: ubuntu-latest | ||
if: (github.event.pull_request.merged == true) && (startsWith(github.event.pull_request.title, 'Release:')) | ||
steps: | ||
- run: | | ||
echo ${{ github.event.pull_request.title}} | ||
echo "TAG=$(echo '${{ github.event.pull_request.title}}' | awk -F '[][]' '{print $2}')" >> $GITHUB_ENV | ||
- name: Checkout | ||
if: "${{ env.TAG }}" | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.REPO_ACCESS }} | ||
|
||
- name: Tagging | ||
if: "${{ env.TAG }}" | ||
run: | | ||
git tag ${{ env.TAG }} | ||
git push origin --tags | ||
- name: Create and publish release on tag | ||
if: "${{ env.TAG }}" | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ github.token }} | ||
script: | | ||
github.rest.repos.createRelease({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
tag_name: "${{ env.TAG }}", | ||
target_commitish: "${{ github.sha}}", | ||
name: "${{ env.TAG }}" | ||
}) | ||
- name: NPM package publish | ||
if: "${{ env.TAG }}" | ||
run: | | ||
npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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,60 @@ | ||
![gitstronaut logo](gitstronaut.jpg) | ||
|
||
## Gitstronaut | ||
|
||
Have a lot of packages on your GitHub account? Explore them smoothly with gitstronaut 🚀 | ||
|
||
### Installation | ||
|
||
This tool needs [NodeJS](https://nodejs.org/en) and it is tested with node version `20.X`. | ||
|
||
```bash | ||
npm i -g gitstronaut | ||
gitstronaut explore | ||
``` | ||
|
||
### Authentication | ||
|
||
There are two ways to authenticate with this CLI: | ||
|
||
- By passing an argument `--token -t` with a (personal or fine-grained) access token from GitHub (required at least read access to repositories and contents) | ||
- If not passing any `--token` argument you will required to grant access to this CLI through your browser with a device code, follow the istructions on your cool terminal | ||
|
||
### Explore | ||
|
||
Usage: | ||
|
||
```bash | ||
gitstronaut explore [--ARGS] | ||
``` | ||
|
||
With explore, for each repository, gitstronaut will give you information about: | ||
|
||
- Branches: warning you about un-protected and pending branches | ||
- Pull requests: warning you about Pull Requests that are open and not merged | ||
- Tags: warning you when the default branch is not aligned with the latest tag (and how many commits are between the two) | ||
|
||
If you're using [changelogger](https://github.com/ctinnovation/changelogger) for handling your CHANGELOGs gitstronaut will also hint you the likely next release needed for that repo. | ||
|
||
|
||
### Tags | ||
|
||
Usage: | ||
|
||
```bash | ||
gitstronaut tags [--ARGS] | ||
``` | ||
|
||
With tags command gitstraonaut will summarize the latest tag for each repo and if the default branch is aligned with it or not. | ||
|
||
|
||
### Arguments | ||
|
||
| Argument | Description | Type | | ||
| ------------------ | ------------------------------------------------------- | -------------------------- | | ||
| -f, --filter | Explore repositories with this filter (RegExp accepted) | | | ||
| -o, --organization | Explore repositories whitin orgaizationb | [string] | | ||
| --showUrls | Show URL of referred data (more verbose) | [boolean] [default: false] | | ||
| -t, --token | Token for access to GitHub | [string] | | ||
| --help | Show help | [boolean] | | ||
| --version | Show version number | [boolean] | |
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,74 @@ | ||
export function iterateRepos (argv, octo) { | ||
const { organization } = argv | ||
|
||
if (organization) { | ||
return octo.paginate.iterator( | ||
octo.rest.repos.listForOrg, | ||
{ org: organization } | ||
) | ||
} else { | ||
return octo.paginate.iterator( | ||
octo.rest.repos.listForAuthenticatedUser, | ||
{ org: organization } | ||
) | ||
} | ||
} | ||
|
||
export async function listTags (argv, octo, params) { | ||
return await octo.paginate( | ||
octo.rest.repos.listTags, | ||
params | ||
) | ||
} | ||
|
||
export async function listCommits (argv, octo, params) { | ||
return await octo.paginate( | ||
octo.rest.repos.listCommits, | ||
params | ||
) | ||
} | ||
|
||
export async function listBranches (argv, octo, params) { | ||
return await octo.paginate( | ||
octo.rest.repos.listBranches, | ||
params | ||
) | ||
} | ||
|
||
export async function listPRs (argv, octo, params) { | ||
return await octo.paginate( | ||
octo.rest.pulls.list, | ||
params | ||
) | ||
} | ||
|
||
export async function listCommitsBetween (argv, octo, params, tagSha, branch) { | ||
const response = await octo.rest.repos.listCommits({ | ||
...params, | ||
sha: branch, | ||
per_page: 30 | ||
}) | ||
const commits = response.data | ||
const result = [] | ||
|
||
for (let i = 0; i < commits.length; i++) { | ||
const { sha } = commits[i] | ||
if (sha === tagSha) { | ||
return result | ||
} | ||
|
||
result.push(commits[i]) | ||
} | ||
|
||
result.exceeding = true | ||
return result | ||
} | ||
|
||
export async function getStaticContent (argv, octo, params, branch) { | ||
const response = await octo.rest.repos.getContent({ | ||
...params, | ||
ref: branch | ||
}) | ||
|
||
return response.data | ||
} |
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,57 @@ | ||
import { iterateRepos, listBranches, listCommitsBetween, listPRs, listTags } from '../api.mjs' | ||
import { buildOcto } from '../octokit.mjs' | ||
import { printHome, printRepo } from '../print.mjs' | ||
import { cliui } from '@poppinss/cliui' | ||
|
||
export default async function run (argv) { | ||
printHome() | ||
|
||
const octo = await buildOcto(argv) | ||
const ui = cliui() | ||
const spinner = ui.logger.await(`Fetching ${argv.organization || 'your'} repos`).start() | ||
|
||
spinner.stop() | ||
|
||
for await (const response of iterateRepos(argv, octo)) { | ||
for (const repo of response.data) { | ||
const filterRegex = new RegExp(argv.filter) | ||
if (argv.filter && !(filterRegex.test(repo.name))) { | ||
continue | ||
} | ||
|
||
const branches = await listBranches(argv, octo, { | ||
owner: repo.owner.login, | ||
repo: repo.name | ||
}) | ||
|
||
const prs = await listPRs(argv, octo, { | ||
owner: repo.owner.login, | ||
repo: repo.name, | ||
state: 'open' | ||
}) | ||
|
||
const tags = await listTags(argv, octo, { | ||
owner: repo.owner.login, | ||
repo: repo.name | ||
}) | ||
|
||
let commitsUntilLatestTag = [] | ||
|
||
if (tags.length) { | ||
const latestTag = tags[0] | ||
const { commit } = latestTag | ||
commitsUntilLatestTag = await listCommitsBetween(argv, octo, { | ||
owner: repo.owner.login, | ||
repo: repo.name | ||
}, commit.sha, repo.default_branch) | ||
} | ||
|
||
await printRepo(argv, octo, repo, { | ||
branches, | ||
prs, | ||
tags, | ||
commitsUntilLatestTag | ||
}) | ||
} | ||
} | ||
} |
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,28 @@ | ||
import run from './handler.mjs' | ||
|
||
const command = ['explore'] | ||
const describe = 'Explore repositories with gitstronaut' | ||
const builder = function (yargs) { | ||
return yargs | ||
.string('token') | ||
.alias('t', 'token') | ||
.describe('token', 'Token for access to GitHub') | ||
.string('organization') | ||
.alias('o', 'organization') | ||
.describe('organization', 'Explore repositories whitin orgaizationb') | ||
.string('filter') | ||
.default('filter', '') | ||
.alias('f', 'filter') | ||
.describe('filter', 'Explore repositories with this filter (RegExp accepted)') | ||
.boolean('showUrls') | ||
.describe('showUrls', 'Show URL of referred data') | ||
.default('showUrls', false) | ||
} | ||
const handler = run | ||
|
||
export default { | ||
command, | ||
describe, | ||
builder, | ||
handler | ||
} |
Oops, something went wrong.