-
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.
✨ (scripts) pullRequest export update
- Loading branch information
1 parent
0e78ee8
commit 764998a
Showing
12 changed files
with
147 additions
and
77 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
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
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
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
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
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,66 +1,100 @@ | ||
#!/usr/bin/env node | ||
#!/usr/bin/env | ||
const { execSync } = require('child_process') | ||
|
||
import { Octokit } from '@octokit/rest' | ||
import chalkPipe from 'chalk-pipe' | ||
import isCI from 'is-ci' | ||
const { Octokit } = require('@octokit/rest') | ||
const chalkPipe = require('chalk-pipe') | ||
const isCI = require('is-ci') | ||
|
||
import { version } from '../package.json' | ||
import PULL_REQUEST__RELEASE from '../templates/PULL_REQUEST__RELEASE' | ||
!isCI && require('dotenv').config({ path: './.env' }) | ||
const PULL_REQUEST__GITFLOW = require('../templates/PULL_REQUEST__GITFLOW') | ||
|
||
const octokit = new Octokit({ auth: process.env.GH_TOKEN }) | ||
const getVersion = (version) => { | ||
const [major, minor, patch] = version.split('-')[0].split('.') | ||
return [parseInt(major), parseInt(minor), parseInt(patch)].join('.') | ||
} | ||
|
||
const owner = process.env.REPO_OWNER | ||
const repo = process.env.REPO_REPO | ||
async function setPullRequest({ head, labels, repo_id, version, q }) { | ||
try { | ||
// @note(ci) assumes travis keeps us honest when this runs | ||
const base = isMain ? 'develop' : 'main' | ||
const bodyTemplate = PULL_REQUEST__GITFLOW() | ||
const titleTemplate = `merge: 🔀️ v{version} => {base} [gitflow] [skip ci]` | ||
|
||
const base = 'main' | ||
const head = 'feature/github-templates' | ||
const toStore = isMain ? 'Release' : 'Submit' | ||
|
||
const bodyTemplate = PULL_REQUEST__RELEASE() | ||
const titleTemplate = `merge: 🔀️ v{version} => {base} [gitflow] [skip ci]` | ||
const body = bodyTemplate | ||
.replace(/\{base\}/g, base) | ||
.replace(/\{head\}/g, head) | ||
.replace(/\{toStore\}/g, toStore) | ||
.replace(/\{version\}/g, version) | ||
|
||
const toStore = base === 'main' ? 'Release' : 'Submit' | ||
const title = titleTemplate | ||
.replace(/\{base\}/g, base) | ||
.replace(/\{head\}/g, head) | ||
.replace(/\{toStore\}/g, toStore) | ||
.replace(/\{version\}/g, version) | ||
|
||
const body = bodyTemplate | ||
.replace(/\{base\}/g, base) | ||
.replace(/\{head\}/g, head) | ||
.replace(/\{toStore\}/g, toStore) | ||
.replace(/\{version\}/g, version) | ||
const response = await octokit.rest.search.issuesAndPullRequests({ | ||
q, | ||
}) | ||
const doesGitflowPrExists = !!response.data && response.data.total_count === 1 | ||
if (doesGitflowPrExists) { | ||
const pr = response.data.items[0] | ||
const pull_number = pr.number | ||
const issue_number = pull_number | ||
console.log( | ||
chalkPipe('orange.bold')( | ||
`🤔️ ${pull_number} => Exists, should we update PR?` | ||
) | ||
) | ||
console.log(chalkPipe('orange.bold')(`🤪️ Right now we are not`)) | ||
console.log( | ||
chalkPipe('orange.bold')( | ||
`😵️ https://github.com/${repo_id}/pull/${pull_number}` | ||
) | ||
) | ||
|
||
const title = titleTemplate | ||
.replace(/\{base\}/g, base) | ||
.replace(/\{head\}/g, head) | ||
.replace(/\{toStore\}/g, toStore) | ||
.replace(/\{version\}/g, version) | ||
// await octokit.rest.pulls.update({ | ||
// owner, | ||
// repo, | ||
// head, | ||
// base, | ||
// title, | ||
// body, | ||
// pull_number, | ||
// }); | ||
|
||
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)) | ||
// await octokit.rest.issues.setLabels({ | ||
// owner, | ||
// repo, | ||
// issue_number, | ||
// labels, | ||
// }); | ||
} else { | ||
console.log(chalkPipe('blue.bold')(`🤠️ Yee-haw, Create a Pee-Ahr`)) | ||
console.log(chalkPipe('blue.bold')(`🤓️ ${title}`)) | ||
|
||
const pull = await octokit.rest.pulls.create({ | ||
owner, | ||
repo, | ||
head, | ||
base, | ||
title, | ||
body, | ||
}) | ||
|
||
octokit.rest.issues.addLabels({ | ||
owner, | ||
repo, | ||
issue_number: pull.data.number, | ||
labels, | ||
}) | ||
} | ||
} catch (error) { | ||
console.log(chalkPipe('red.bold')(`❎️ error: ${owner}/${repo} => pr`)) | ||
// console.log(chalkPipe('white.italic')(error)) | ||
console.log(chalkPipe('red.bold')(`❎️ error: ${owner}/${repo} => pulls.list`)) | ||
console.log(chalkPipe('white.italic')(error)) | ||
} | ||
} | ||
|
||
pullRequest() | ||
module.exports = setPullRequest |
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,17 @@ | ||
import labels from './data/labels' | ||
import milestones from './data/milestones' | ||
import githubLabel from './github/label' | ||
import githubMilestone from './github/milestone' | ||
import githubPullRequest from './github/pullRequest' | ||
import templatePullRequestRelease from './templates/PULL_REQUEST__RELEASE' | ||
import { space } from './utils/getChars' | ||
|
||
export { | ||
labels, | ||
milestones, | ||
githubLabel, | ||
githubMilestone, | ||
githubPullRequest, | ||
templatePullRequestRelease, | ||
space, | ||
} |
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
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"module": "commonjs", | ||
"noEmit": false, | ||
"outDir": "../dist", | ||
"paths": {}, | ||
"noUnusedParameters": false, // @todo(lint) | ||
"resolveJsonModule": true, | ||
"rootDir": ".", | ||
"strict": false, | ||
"target": "ES6" | ||
}, | ||
"exclude": ["node_modules"], | ||
"extends": "../../codestyle/tsconfig.react.json", | ||
"includes": ["**/*.js"], | ||
"references": [{ "path": "../" }] | ||
} |
File renamed without changes.
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 @@ | ||
import { version } from '../../package.json' | ||
|
||
export { version } |
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,16 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"module": "commonjs", | ||
"noEmit": false, | ||
"outDir": "./dist", | ||
"paths": {}, | ||
"noUnusedParameters": false, // @todo(lint) | ||
"rootDir": "./src", | ||
"strict": false, | ||
"target": "ES6" | ||
"rootDir": ".", | ||
"outDir": ".", | ||
"resolveJsonModule": true, | ||
"composite": true | ||
}, | ||
"exclude": ["node_modules"], | ||
"extends": "../codestyle/tsconfig.react.json", | ||
"include": ["src/**/*.js", "src/**/*.ts"] | ||
"files": ["package.json"] | ||
} |