@monoweave/plugin-github 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +9 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +9 -0
- package/lib/plugin.d.ts +12 -0
- package/lib/plugin.js +79 -0
- package/lib/request.d.ts +2 -0
- package/lib/request.js +7 -0
- package/package.json +49 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
<!-- MONOWEAVE:BELOW -->
|
|
4
|
+
|
|
5
|
+
## [2.0.2](https://github.com/monoweave/monoweave/compare/@monoweave/plugin-github@2.0.1...@monoweave/plugin-github@2.0.2) "@monoweave/plugin-github" (2024-02-29)<a name="2.0.2"></a>
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* initial commit, forked from tophat/monodeploy under Apache 2.0 license (#1) ([2410d1c](https://github.com/monoweave/monoweave/commits/2410d1c))
|
|
10
|
+
|
|
11
|
+
|
package/README.md
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type PluginHooks } from '@monoweave/types';
|
|
2
|
+
export declare const PluginName = "GitHub Plugin";
|
|
3
|
+
import { type PluginOptions } from './plugin';
|
|
4
|
+
export default function GitHubPlugin({ onReleaseAvailable }: Pick<PluginHooks, 'onReleaseAvailable'>, options?: PluginOptions | undefined): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginName = void 0;
|
|
4
|
+
exports.PluginName = 'GitHub Plugin';
|
|
5
|
+
const plugin_1 = require("./plugin");
|
|
6
|
+
function GitHubPlugin({ onReleaseAvailable }, options) {
|
|
7
|
+
onReleaseAvailable.tapPromise(exports.PluginName, (0, plugin_1.createPluginInternals)(options ?? {}));
|
|
8
|
+
}
|
|
9
|
+
exports.default = GitHubPlugin;
|
package/lib/plugin.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ChangesetSchema, type MonoweaveConfiguration, type YarnContext } from '@monoweave/types';
|
|
2
|
+
export declare const PluginName = "GitHub Plugin";
|
|
3
|
+
export interface PluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to create GitHub releases for version updates with no
|
|
6
|
+
* changes.
|
|
7
|
+
*
|
|
8
|
+
* @default {false}
|
|
9
|
+
*/
|
|
10
|
+
includeImplicitUpdates?: boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare const createPluginInternals: (options: PluginOptions) => (context: YarnContext, config: MonoweaveConfiguration, changeset: ChangesetSchema) => Promise<void>;
|
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createPluginInternals = exports.PluginName = void 0;
|
|
7
|
+
const git_1 = require("@monoweave/git");
|
|
8
|
+
const logging_1 = __importDefault(require("@monoweave/logging"));
|
|
9
|
+
const core_1 = require("@octokit/core");
|
|
10
|
+
const plugin_throttling_1 = require("@octokit/plugin-throttling");
|
|
11
|
+
const request_1 = require("./request");
|
|
12
|
+
exports.PluginName = 'GitHub Plugin';
|
|
13
|
+
const createPluginInternals = (options) => async (context, config, changeset) => {
|
|
14
|
+
const personalAccessToken = process.env.GH_TOKEN;
|
|
15
|
+
if (!personalAccessToken) {
|
|
16
|
+
throw new Error('Missing GitHub Personal Access Token');
|
|
17
|
+
}
|
|
18
|
+
const ThrottledOctokit = core_1.Octokit.plugin(plugin_throttling_1.throttling);
|
|
19
|
+
const octokit = new ThrottledOctokit({
|
|
20
|
+
auth: personalAccessToken,
|
|
21
|
+
throttle: {
|
|
22
|
+
onRateLimit: () => true,
|
|
23
|
+
onSecondaryRateLimit: () => false,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
const { owner, repository: repo } = await (0, git_1.parseRepositoryProperty)(context.workspace);
|
|
27
|
+
if (!owner || !repo) {
|
|
28
|
+
throw new Error('Cannot determine GitHub owner or repository');
|
|
29
|
+
}
|
|
30
|
+
const changesByTag = new Map();
|
|
31
|
+
for (const [pkgName, changeData] of Object.entries(changeset)) {
|
|
32
|
+
const tag = changeData.tag;
|
|
33
|
+
if (!tag) {
|
|
34
|
+
throw new Error(`Missing package git tag for ${pkgName}`);
|
|
35
|
+
}
|
|
36
|
+
let changelog = changeData.changelog;
|
|
37
|
+
if (options.includeImplicitUpdates) {
|
|
38
|
+
changelog = 'Implicit version bump due to dependency updates.';
|
|
39
|
+
}
|
|
40
|
+
if (!changelog) {
|
|
41
|
+
logging_1.default.info(`[${exports.PluginName}] Skipping release for ${changeData.tag} as there's no changelog.`, {
|
|
42
|
+
report: context.report,
|
|
43
|
+
});
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const changes = changesByTag.get(tag) ?? [];
|
|
47
|
+
changes.push({ ...changeData, name: pkgName, changelog });
|
|
48
|
+
changesByTag.set(tag, changes);
|
|
49
|
+
}
|
|
50
|
+
const sortedEntries = Array.from(changesByTag.entries()).sort(([tagA, changesA], [tagB, changesB]) => {
|
|
51
|
+
// sort by number of changes in descending order, then by name, reversed so the release with
|
|
52
|
+
// largest number of changes appears first in GitHub.
|
|
53
|
+
if (changesA.length === changesB.length) {
|
|
54
|
+
return tagB.localeCompare(tagA);
|
|
55
|
+
}
|
|
56
|
+
return changesB.length - changesA.length;
|
|
57
|
+
});
|
|
58
|
+
for (const [tag, changes] of sortedEntries) {
|
|
59
|
+
logging_1.default.info(`[${exports.PluginName}] Creating release for ${tag}`, {
|
|
60
|
+
report: context.report,
|
|
61
|
+
});
|
|
62
|
+
if (config.dryRun)
|
|
63
|
+
continue;
|
|
64
|
+
const combinedChangelog = changes
|
|
65
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
66
|
+
.map((change) => change.changelog)
|
|
67
|
+
.join('\n');
|
|
68
|
+
await (0, request_1.request)(octokit, 'POST /repos/{owner}/{repo}/releases', {
|
|
69
|
+
owner,
|
|
70
|
+
repo,
|
|
71
|
+
tag_name: tag,
|
|
72
|
+
name: tag,
|
|
73
|
+
body: combinedChangelog,
|
|
74
|
+
draft: false,
|
|
75
|
+
prerelease: config.prerelease,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.createPluginInternals = createPluginInternals;
|
package/lib/request.d.ts
ADDED
package/lib/request.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@monoweave/plugin-github",
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/monoweave/monoweave.git",
|
|
7
|
+
"directory": "packages/plugin-github"
|
|
8
|
+
},
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "noahnu",
|
|
11
|
+
"url": "https://monoweave.github.io"
|
|
12
|
+
},
|
|
13
|
+
"license": "BSD-3",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"main": "./lib/index.js",
|
|
16
|
+
"registry": "https://registry.npmjs.org/",
|
|
17
|
+
"types": "./lib/index.d.ts",
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"main": "./lib/index.js",
|
|
21
|
+
"files": [
|
|
22
|
+
"lib"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clean": "run workspace:clean \"$(pwd)\"",
|
|
26
|
+
"types:watch": "run workspace:types:watch \"$(pwd)\"",
|
|
27
|
+
"test:watch": "run workspace:test:watch \"$(pwd)\"",
|
|
28
|
+
"build:watch": "run workspace:build:watch \"$(pwd)\"",
|
|
29
|
+
"prepack": "run workspace:build \"$(pwd)\""
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@monoweave/test-utils": "link:../../testUtils",
|
|
33
|
+
"@types/jest": "^29.5.6",
|
|
34
|
+
"@types/node": "^18.18.6",
|
|
35
|
+
"tapable": "^2.2.1"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@monoweave/git": "^0.0.2",
|
|
39
|
+
"@monoweave/io": "^0.0.2",
|
|
40
|
+
"@monoweave/logging": "^0.0.2",
|
|
41
|
+
"@monoweave/types": "^0.0.2",
|
|
42
|
+
"@octokit/core": "^5.0.1",
|
|
43
|
+
"@octokit/plugin-throttling": "^8.1.2",
|
|
44
|
+
"@yarnpkg/core": "^4.0.3",
|
|
45
|
+
"@yarnpkg/fslib": "^3.0.2",
|
|
46
|
+
"@yarnpkg/shell": "^4.0.0"
|
|
47
|
+
},
|
|
48
|
+
"types": "./lib/index.d.ts"
|
|
49
|
+
}
|