-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ @jeromefitz/scripts => first hack github
Foundation of scripts to use in CI/CD processes to init repos, as well as hook into PR creation and milestone updates for Sprints
- Loading branch information
1 parent
a223e96
commit e0f71ef
Showing
11 changed files
with
368 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,43 @@ | ||
{ | ||
"name": "@jeromefitz/scripts", | ||
"version": "2.0.0-canary.3", | ||
"description": "Scripts", | ||
"author": { | ||
"name": "Jerome Fitzgerald", | ||
"email": "j@jeromefitzgerald.com", | ||
"url": "https://jeromefitzgerald.com" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "ssh://git@github.com/jeromefitz/packages.git", | ||
"directory": "packages/scripts" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"private": false, | ||
"scripts": { | ||
"build": "tsc", | ||
"lint-eslint": "eslint . --ext js,jsx,ts,tsx --max-warnings=0", | ||
"lint-fix": "yarn prettier-fix && eslint . --ext js,jsx,ts,tsx --fix --max-warnings=0", | ||
"lint-typescript": "yarn typescript", | ||
"lint": "yarn lint-typescript && yarn prettier-check && yarn lint-eslint", | ||
"tsc:watch": "tsc -w --preserveWatchOutput", | ||
"prettier-check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md,mdx,css,html,yml,yaml,scss}\"", | ||
"prettier-fix": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,mdx,css,html,yml,yaml,scss}\"", | ||
"pretty-quick": "pretty-quick", | ||
"typescript": "tsc --noEmit --declaration" | ||
}, | ||
"devDependecies": { | ||
"@jeromefitz/codestyle": "2.0.0-canary.3", | ||
"typescript": "4.1.5" | ||
}, | ||
"dependencies": { | ||
"@octokit/rest": "18.5.3" | ||
}, | ||
"files": [ | ||
"dist/", | ||
"index.js" | ||
] | ||
} |
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,5 @@ | ||
const isCI = require('is-ci') | ||
!isCI && require('dotenv').config({ path: './.env' }) | ||
|
||
const release = require('../semantic/release.config.js') | ||
module.exports = { ...release } |
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,92 @@ | ||
// ref: https://octokit.github.io/rest.js/v18#issues-create-label | ||
|
||
const labels = [ | ||
{ | ||
name: 'Awaiting 3rd Party', | ||
emoji: '3️⃣️', | ||
description: 'WIP: Waiting on 3rd Party Updates', | ||
color: 'EAB820', | ||
}, | ||
{ | ||
name: 'Awaiting Code Review (Priority)', | ||
emoji: '⏲️', | ||
description: 'Please look at this PR first for code reviews', | ||
color: 'EDD674', | ||
}, | ||
{ | ||
name: 'Bug', | ||
emoji: '🐛️', | ||
description: 'Something isn’t working', | ||
color: 'D8EBF6', | ||
}, | ||
{ | ||
name: 'Changes Requested', | ||
emoji: '♻️', | ||
description: 'Please address any changes requested to the PR', | ||
color: 'ECD9BA', | ||
}, | ||
{ | ||
name: 'Conflicts', | ||
emoji: '🛠️', | ||
color: 'C2E0C6', | ||
description: 'Please address merge conflicts', | ||
}, | ||
{ | ||
name: 'Dependencies', | ||
emoji: '📦️', | ||
description: 'Pull requests that update a dependency file', | ||
color: 'E8F1FA', | ||
}, | ||
|
||
{ | ||
name: 'DNM: Awaiting Scheduling', | ||
emoji: '🗓️', | ||
description: 'Please review, hold on merging', | ||
color: '7057ff', | ||
}, | ||
{ | ||
name: 'Duplicate', | ||
emoji: '💕️', | ||
description: 'Identified to be closed when determined which should be merged', | ||
color: 'cccccc', | ||
}, | ||
{ | ||
name: 'Do Not Merge', | ||
emoji: '🛑️', | ||
description: 'Do not merge until further notice', | ||
color: '5e0b82', | ||
}, | ||
{ | ||
name: 'Help Wanted', | ||
emoji: '🤝️', | ||
description: 'Extra attention is needed', | ||
color: '008672', | ||
}, | ||
{ | ||
name: 'LGTM', | ||
emoji: '🥳️', | ||
description: 'Automerge: Let’s Get This Merged', | ||
color: 'D0FD72', | ||
}, | ||
{ | ||
name: 'Question / More Info', | ||
emoji: 'ℹ️', | ||
description: 'Question or More Info on a PR that is not a Change Request', | ||
color: 'FC8DD9', | ||
}, | ||
{ | ||
name: 'Technical Progress', | ||
emoji: '⚛️', | ||
description: | ||
'May not be attributed to a Sprint per se, verify with Milestone before it can be merged', | ||
color: '466B69', | ||
}, | ||
{ | ||
name: 'WIP', | ||
emoji: '🚧️', | ||
description: 'Work in progress, please do not merge / review just yet', | ||
color: 'E4E669', | ||
}, | ||
] | ||
|
||
export default labels |
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,11 @@ | ||
// ref: https://octokit.github.io/rest.js/v18#issues-create-milestone | ||
const milestones = [ | ||
{ | ||
description: 'All PRs that are about that Party Time dood.', | ||
emoji: '🥳️', | ||
name: 'Party Time', | ||
state: 'open', | ||
}, | ||
] | ||
|
||
export default milestones |
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,43 @@ | ||
#!/usr/bin/env node | ||
|
||
import chalkPipe from 'chalk-pipe' | ||
import { Octokit } from '@octokit/rest' | ||
import isCI from 'is-ci' | ||
import getLabels from '../data/labels' | ||
!isCI && require('dotenv').config({ path: './.env' }) | ||
|
||
const octokit = new Octokit({ auth: process.env.GH_TOKEN }) | ||
|
||
const owner = process.env.REPO_OWNER | ||
const repo = process.env.REPO_REPO | ||
|
||
const labels = getLabels.map((label) => ({ | ||
name: `${label.emoji} ${label.name}`, | ||
description: label.description, | ||
color: label.color, | ||
})) | ||
|
||
// @note | ||
// - Potentialy may be to do a`listLabelsForRepo` then `deleteLabel` and just`createLabel` fresh | ||
// - Or `listLabelsForRepo` then create a migration script instead. | ||
async function createLabels() { | ||
try { | ||
labels.map(async (label) => { | ||
await octokit.rest.issues.createLabel({ | ||
owner, | ||
repo, | ||
...label, | ||
}) | ||
console.log( | ||
chalkPipe('green.bold')( | ||
`✅️ success: ${owner}/${repo} => createLabel: ${label.name}` | ||
) | ||
) | ||
}) | ||
} catch (error) { | ||
console.log(chalkPipe('red.bold')(`❎️ error: ${owner}/${repo} => createLabel`)) | ||
// console.log(chalkPipe('white.italic')(error)) | ||
} | ||
} | ||
|
||
createLabels() |
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,42 @@ | ||
#!/usr/bin/env node | ||
|
||
import chalkPipe from 'chalk-pipe' | ||
import { Octokit } from '@octokit/rest' | ||
import isCI from 'is-ci' | ||
import getMilestones from '../data/milestones' | ||
!isCI && require('dotenv').config({ path: './.env' }) | ||
|
||
const octokit = new Octokit({ auth: process.env.GH_TOKEN }) | ||
|
||
const owner = process.env.REPO_OWNER | ||
const repo = process.env.REPO_REPO | ||
|
||
const milestones = getMilestones.map((milestone) => ({ | ||
title: `${milestone.emoji} ${milestone.name}`, | ||
description: milestone.description, | ||
state: milestone.state, | ||
})) | ||
|
||
async function createMilestones() { | ||
try { | ||
milestones.map(async (milestone) => { | ||
await octokit.rest.issues.createMilestone({ | ||
owner, | ||
repo, | ||
...milestone, | ||
}) | ||
console.log( | ||
chalkPipe('green.bold')( | ||
`✅️ success: ${owner}/${repo} => createMilestone: ${milestone.name}` | ||
) | ||
) | ||
}) | ||
} catch (error) { | ||
console.log( | ||
chalkPipe('red.bold')(`❎️ error: ${owner}/${repo} => createMilestone`) | ||
) | ||
// console.log(chalkPipe('white.italic')(error)) | ||
} | ||
} | ||
|
||
createMilestones() |
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,65 @@ | ||
#!/usr/bin/env node | ||
|
||
import chalkPipe from 'chalk-pipe' | ||
import { Octokit } from '@octokit/rest' | ||
import isCI from 'is-ci' | ||
import PULL_REQUEST__RELEASE from '../templates/PULL_REQUEST__RELEASE' | ||
import { version } from '../package.json' | ||
!isCI && require('dotenv').config({ path: './.env' }) | ||
|
||
const octokit = new Octokit({ auth: process.env.GH_TOKEN }) | ||
|
||
const owner = process.env.REPO_OWNER | ||
const repo = process.env.REPO_REPO | ||
|
||
const base = 'main' | ||
const head = 'feature/github-templates' | ||
|
||
const bodyTemplate = PULL_REQUEST__RELEASE() | ||
const titleTemplate = `merge: 🔀️ v{version} => {base} [gitflow] [skip ci]` | ||
|
||
const toStore = base === 'main' ? 'Release' : 'Submit' | ||
|
||
const body = bodyTemplate | ||
.replace(/\{base\}/g, base) | ||
.replace(/\{head\}/g, head) | ||
.replace(/\{toStore\}/g, toStore) | ||
.replace(/\{version\}/g, version) | ||
|
||
const title = titleTemplate | ||
.replace(/\{base\}/g, base) | ||
.replace(/\{head\}/g, head) | ||
.replace(/\{toStore\}/g, toStore) | ||
.replace(/\{version\}/g, version) | ||
|
||
async function pullRequest() { | ||
try { | ||
// const response = await octokit.rest.pulls.create({ | ||
// owner, | ||
// repo, | ||
// head, | ||
// base, | ||
// title, | ||
// body, | ||
// }) | ||
const response = await octokit.rest.pulls.update({ | ||
owner, | ||
repo, | ||
head, | ||
base, | ||
title, | ||
body, | ||
pull_number: 1, | ||
}) | ||
if (!!response.data.body) { | ||
console.log(chalkPipe('green.bold')(`✅️ success: ${owner}/${repo} => pr`)) | ||
// console.log(chalkPipe('white.italic')(response.body)) | ||
console.log(JSON.stringify(response, null, 2)) | ||
} | ||
} catch (error) { | ||
console.log(chalkPipe('red.bold')(`❎️ error: ${owner}/${repo} => pr`)) | ||
// console.log(chalkPipe('white.italic')(error)) | ||
} | ||
} | ||
|
||
pullRequest() |
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,18 @@ | ||
import { space } from '../utils/getChars' | ||
|
||
const PULL_REQUEST__RELEASE = () => { | ||
return `### 🔀️ ${space} **Gitflow Automation:** \`{version} => {base}\` | ||
- [x] 📦️ ${space} **Version**: \`{version}\` | ||
- [x] 🔀️ ${space} **Merge**: \`{head} => {base}\` | ||
- [ ] 🏪️ ${space} **{toStore} to Store** | ||
- [ ] 🍏️ ${space} **Apple:** \`iOS\` | ||
- [ ] 🤖️ ${space} **Google:** \`Android\` | ||
--- | ||
📝️ **Note:** _This PR was automatically generated._ :octocat: | ||
` | ||
} | ||
|
||
export default PULL_REQUEST__RELEASE |
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,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"module": "commonjs", | ||
"noEmit": false, | ||
"outDir": "./dist", | ||
"paths": {}, | ||
"noUnusedParameters": false, // @todo(lint) | ||
"rootDir": "./src", | ||
"strict": false, | ||
"target": "ES6" | ||
}, | ||
"exclude": ["node_modules"], | ||
"extends": "../codestyle/tsconfig.react.json", | ||
"include": ["src/**/*.js", "src/**/*.ts"] | ||
} |
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,3 @@ | ||
const space = ' ' | ||
|
||
module.exports = { space } |
Oops, something went wrong.