-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add task to cleanup docs previews on merge commits (#1647)
Closes #1620
- Loading branch information
1 parent
5a830fd
commit 3de9972
Showing
4 changed files
with
79 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
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,15 @@ | ||
import * as tasks from './tasks'; | ||
import { createBuilder } from './util'; | ||
import { packages } from './config'; | ||
|
||
const cleanup = createBuilder([ | ||
['Cleanup docs previews', tasks.cleanupDocsPreviews], | ||
]); | ||
|
||
cleanup({ | ||
scope: '', | ||
packages, | ||
}).catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
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 |
---|---|---|
|
@@ -149,3 +149,49 @@ export async function postGithubComment() { | |
}); | ||
} | ||
} | ||
|
||
export async function cleanupDocsPreviews() { | ||
const repoUrl = '[email protected]:ngrx/ngrx-io-previews.git'; | ||
const repoDir = `./tmp/docs-preview-cleanup`; | ||
const token = process.env.GITHUB_API_KEY; | ||
const octokit = require('@octokit/rest')(); | ||
|
||
octokit.authenticate({ type: 'token', token }); | ||
|
||
const q = 'repo:ngrx/platform is:pr is:closed'; | ||
|
||
const { data }: { data: { items: any[] } } = await octokit.search.issues({ | ||
q, | ||
per_page: 100, | ||
}); | ||
|
||
await util.cmd('rm -rf', [`${repoDir}`]); | ||
await util.cmd('mkdir ', [`-p ${repoDir}`]); | ||
await process.chdir(`${repoDir}`); | ||
await util.git([`init`]); | ||
await util.git([`remote add origin ${repoUrl}`]); | ||
await util.git([`fetch origin master --depth=1`]); | ||
await util.git(['checkout origin/master -b master']); | ||
|
||
const prsToRemove = data.items.reduce( | ||
(prev: string[], curr: { number: number }) => { | ||
prev.push(`pr${curr.number}*`); | ||
|
||
return prev; | ||
}, | ||
[] | ||
); | ||
|
||
await util.cmd('rm -rf', [`${prsToRemove.join(' ')}`]); | ||
await util.git([`config user.name "ngrxbot"`]); | ||
await util.git([`config user.email "${process.env.GITHUB_BOT_EMAIL}"`]); | ||
await util.git(['add --all']); | ||
|
||
try { | ||
await util.git([ | ||
`commit -m "chore: cleanup previews for closed pull requests"`, | ||
]); | ||
} catch (e) {} | ||
|
||
await util.git(['push origin master --force']); | ||
} |
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