Skip to content

Commit fbb968b

Browse files
Slackbot:release (#1875)
* initial port to cli * mv release-bot to subdir * Updates error logging * creates getRootPackageJson * adds slackbot tests * fix lint * rm commander * bot support for other repos. adds tests * fix lint * add slackbot as dep to cli * Update index.ts * Update index.ts * Update index.ts * fix package versions * Use fs-extra * export isValidJSON from meta * Fixes slackbot tests
1 parent 6815ee6 commit fbb968b

29 files changed

+427
-135
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lg-tools/meta': patch
3+
---
4+
5+
Exports `isValidJSON` utility

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"lint": "lg lint",
2525
"prepublishOnly": "yarn build",
2626
"publish": "yarn changeset publish --public",
27-
"slackbot": "lg slackbot",
27+
"slackbot": "lg slackbot release",
2828
"start": "storybook dev -p 9001 --no-version-updates",
2929
"test": "lg test",
3030
"unlink": "lg unlink",

tools/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@lg-tools/install": "0.1.2",
2222
"@lg-tools/link": "0.1.2",
2323
"@lg-tools/lint": "0.1.3",
24+
"@lg-tools/slackbot": "0.1.1",
2425
"@lg-tools/test": "0.2.2",
2526
"@lg-tools/update": "0.1.2",
2627
"@lg-tools/validate": "0.1.2",

tools/cli/src/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createPackage } from '@lg-tools/create';
33
import { installLeafyGreen } from '@lg-tools/install';
44
import { linkPackages, unlinkPackages } from '@lg-tools/link';
55
import { lint } from '@lg-tools/lint';
6+
import { releaseBot } from '@lg-tools/slackbot';
67
import { test } from '@lg-tools/test';
78
import { update } from '@lg-tools/update';
89
import { validate } from '@lg-tools/validate';
@@ -67,6 +68,37 @@ cli
6768
.option('--scope <name>', 'The NPM organization')
6869
.action(unlinkPackages);
6970

71+
/** Slackbot */
72+
const slackbotCmd = cli.command('slackbot');
73+
74+
/**
75+
* This command is run by GitHub Actions immediately after \`changeset\`.
76+
*
77+
* Must have the \`.env\` variable "SLACK_BOT_TOKEN" set.
78+
* This is the "Bot User OAuth Token" found at https://api.slack.com/apps/A02H2UGAMDM/oauth, and should start with "xoxb-"
79+
*
80+
* To run this automatically, pass in an array of updates (in the format output by \`changeset\`) as the first argument.
81+
* i.e. \`yarn slackbot '[{"name": "@leafygreen-ui/sample", "version": "0.1.0"}]' \`
82+
*
83+
* Optionally pass in a channel name (defaults to 'leafygreen-ui-releases').
84+
* Valid channels are: \`${Object.keys(Channels).join('`, `')}\`.
85+
*/
86+
slackbotCmd
87+
.command('release')
88+
.arguments('[updates]')
89+
.description(
90+
'Notifies the MongoDB leafygreen-ui releases channel of any new packages.',
91+
)
92+
.option('-t, --test', 'Post to `design-system-testing`', false)
93+
.option('-d, --dry', 'Dry run. Does not post', false)
94+
.option('-v --verbose', 'Prints additional information to the console', false)
95+
.option(
96+
'-c, --channel <channel>',
97+
'Channel to post to.',
98+
'leafygreen-ui-releases',
99+
)
100+
.action(releaseBot);
101+
70102
/** Lint */
71103
cli
72104
.command('lint')

tools/cli/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
{
2727
"path": "../lint"
2828
},
29+
{
30+
"path": "../slackbot"
31+
},
2932
{
3033
"path": "../test"
3134
},
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import fse from 'fs-extra';
2+
import path from 'path';
3+
4+
export function getRootPackageJson(): Record<string, any> | undefined {
5+
const rootDir = process.cwd();
6+
const pkgJsonPath = path.resolve(rootDir, 'package.json');
7+
const pkgJsonStr = fse.readFileSync(pkgJsonPath, 'utf-8');
8+
9+
if (isValidJSON(pkgJsonStr)) {
10+
return JSON.parse(pkgJsonStr);
11+
}
12+
}
13+
14+
export function isValidJSON(str?: string): boolean {
15+
if (!str) return false;
16+
17+
try {
18+
JSON.parse(str);
19+
return true;
20+
} catch (error) {
21+
return false;
22+
}
23+
}

tools/meta/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { getAllPackageNames, getAllPackages } from './getAllPackages';
22
export { getLGConfig, type LGConfig } from './getLGConfig';
33
export { getPackageManager } from './getPackageManager';
44
export { getPackageName } from './getPackageName';
5+
export { getRootPackageJson, isValidJSON } from './getRootPackageJson';

tools/slackbot/README.md

Whitespace-only changes.

tools/slackbot/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"bin": {
77
"lg-slackbot": "./bin/slackbot.js"
88
},
9+
"main": "dist/index.js",
10+
"module": "dist/esm/index.js",
911
"scripts": {
1012
"build": "lg-internal-build-package",
1113
"tsc": "tsc --build tsconfig.json"
@@ -15,10 +17,10 @@
1517
},
1618
"dependencies": {
1719
"@lg-tools/build": "^0.2.0",
18-
"@slack/web-api": "^6.4.0",
19-
"chalk": "^4.1.2",
20-
"commander": "^11.0.0",
21-
"lodash": "^4.17.21",
22-
"node-fetch": "^2.6.1"
20+
"@lg-tools/meta": "^0.1.2",
21+
"@slack/web-api": "6.7.1",
22+
"chalk": "4.1.2",
23+
"lodash": "4.17.21",
24+
"node-fetch": "2.6.11"
2325
}
2426
}

tools/slackbot/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import './slackbot';
1+
export { Channels, releaseBot } from './release-bot';

0 commit comments

Comments
 (0)