@jpmorganchase/mosaic-workflows 0.1.0-beta.6
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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BitbucketSourceOptions } from '@jpmorganchase/mosaic-source-bitbucket';
|
|
2
|
+
import type { SourceWorkflow } from '@jpmorganchase/mosaic-types';
|
|
3
|
+
interface BitBucketPullRequestWorkflowOptions {
|
|
4
|
+
apiEndpoint: string;
|
|
5
|
+
commitMessage: (filePath: string) => string;
|
|
6
|
+
titlePrefix: string;
|
|
7
|
+
}
|
|
8
|
+
declare const workflow: SourceWorkflow<BitbucketSourceOptions, BitBucketPullRequestWorkflowOptions>;
|
|
9
|
+
export default workflow;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const mosaic_source_bitbucket_1 = require("@jpmorganchase/mosaic-source-bitbucket");
|
|
10
|
+
const mdx_1 = __importDefault(require("@jpmorganchase/mosaic-serialisers/dist/mdx"));
|
|
11
|
+
let repoInstance = null;
|
|
12
|
+
async function createPullRequest(sourceOptions, { apiEndpoint, commitMessage, titlePrefix }, filePath, { user, markdown }) {
|
|
13
|
+
const { credentials, remote, branch: sourceBranch, repo: repoUrl, subfolder, prefixDir } = sourceOptions;
|
|
14
|
+
if (!repoUrl || !markdown) {
|
|
15
|
+
// indicate to the plugin runner that no save happened
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (!repoInstance) {
|
|
19
|
+
repoInstance = new mosaic_source_bitbucket_1.Repo(credentials, remote, sourceBranch, repoUrl);
|
|
20
|
+
await repoInstance.init();
|
|
21
|
+
}
|
|
22
|
+
const branchName = `${user.sid.toLowerCase()}-${(0, uuid_1.v4)()}`;
|
|
23
|
+
await repoInstance.createWorktree(user.sid.toLowerCase(), branchName);
|
|
24
|
+
/**
|
|
25
|
+
* strip out the namespace from the file path.
|
|
26
|
+
* We are interested in the file on disk not in the VFS
|
|
27
|
+
*/
|
|
28
|
+
const pathOnDisk = path_1.default.posix.join(repoInstance.dir, subfolder, filePath.replace(new RegExp(`${prefixDir}/`), ''));
|
|
29
|
+
const rawPage = await fs_1.default.promises.readFile(pathOnDisk);
|
|
30
|
+
const { content, ...metadata } = await mdx_1.default.deserialise(pathOnDisk, rawPage);
|
|
31
|
+
const updatedPage = { ...metadata, content: markdown };
|
|
32
|
+
await fs_1.default.promises.writeFile(pathOnDisk, await mdx_1.default.serialise(pathOnDisk, updatedPage));
|
|
33
|
+
const bitBucketRequest = JSON.stringify({
|
|
34
|
+
title: `${titlePrefix} - Content update - ${filePath}`,
|
|
35
|
+
fromRef: {
|
|
36
|
+
id: `refs/heads/${branchName}`,
|
|
37
|
+
repository: {
|
|
38
|
+
slug: `${repoInstance.repoName}`,
|
|
39
|
+
name: null,
|
|
40
|
+
project: {
|
|
41
|
+
key: `${repoInstance.projectName}`
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
toRef: {
|
|
46
|
+
id: `refs/heads/${sourceBranch}`,
|
|
47
|
+
repository: {
|
|
48
|
+
slug: `${repoInstance.repoName}`,
|
|
49
|
+
name: null,
|
|
50
|
+
project: {
|
|
51
|
+
key: `${repoInstance.projectName}`
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const endpoint = `${apiEndpoint}/projects/${repoInstance.projectName}/repos/${repoInstance.repoName}/pull-requests`;
|
|
57
|
+
return repoInstance.createPullRequest(user, branchName, filePath, endpoint, bitBucketRequest, commitMessage(filePath));
|
|
58
|
+
}
|
|
59
|
+
const workflow = {
|
|
60
|
+
name: 'save',
|
|
61
|
+
options: {
|
|
62
|
+
titlePrefix: 'Mosaic Docs',
|
|
63
|
+
apiEndpoint: process.env.BITBUCKET_API_URL || '',
|
|
64
|
+
commitMessage: (filePath) => `docs: updated content ${filePath} (UIE-7026)`
|
|
65
|
+
},
|
|
66
|
+
action: createPullRequest
|
|
67
|
+
};
|
|
68
|
+
exports.default = workflow;
|
|
69
|
+
//# sourceMappingURL=BitBucketPullRequestWorkflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitBucketPullRequestWorkflow.js","sourceRoot":"","sources":["../src/BitBucketPullRequestWorkflow.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,4CAAoB;AACpB,+BAAoC;AACpC,oFAAsF;AACtF,qFAAwE;AAcxE,IAAI,YAAY,GAAgB,IAAI,CAAC;AAErC,KAAK,UAAU,iBAAiB,CAC9B,aAAqC,EACrC,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAuC,EAChF,QAAgB,EAChB,EAAE,IAAI,EAAE,QAAQ,EAAoC;IAEpD,MAAM,EACJ,WAAW,EACX,MAAM,EACN,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,OAAO,EACb,SAAS,EACT,SAAS,EACV,GAAG,aAAa,CAAC;IAElB,IAAI,CAAC,OAAO,IAAI,CAAC,QAAQ,EAAE;QACzB,sDAAsD;QACtD,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,YAAY,EAAE;QACjB,YAAY,GAAG,IAAI,8BAAI,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QACpE,MAAM,YAAY,CAAC,IAAI,EAAE,CAAC;KAC3B;IAED,MAAM,UAAU,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,IAAA,SAAM,GAAE,EAAE,CAAC;IAC3D,MAAM,YAAY,CA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EAAE;iBACnC;aACF;SACF;KACF,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,GAAG,WAAW,aAAa,YAAY,CAAC,WAAW,UAAU,YAAY,CAAC,QAAQ,gBAAgB,CAAC;IAEpH,OAAO,YAAY,CAAC,iBAAiB,CACnC,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,aAAa,CAAC,QAAQ,CAAC,CACxB,CAAC;AACJ,CAAC;AAED,MAAM,QAAQ,GAAgF;IAC5F,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE;QACP,WAAW,EAAE,aAAa;QAC1B,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE;QAChD,aAAa,EAAE,CAAC,QAAgB,EAAE,EAAE,CAAC,yBAAyB,QAAQ,aAAa;KACpF;IACD,MAAM,EAAE,iBAAiB;CAC1B,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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.BitBucketPullRequestWorkflow = void 0;
|
|
7
|
+
const BitBucketPullRequestWorkflow_1 = __importDefault(require("./BitBucketPullRequestWorkflow"));
|
|
8
|
+
exports.BitBucketPullRequestWorkflow = BitBucketPullRequestWorkflow_1.default;
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,kGAA0E;AAEjE,uCAFF,sCAA4B,CAEE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jpmorganchase/mosaic-workflows",
|
|
3
|
+
"version": "0.1.0-beta.6",
|
|
4
|
+
"author": "",
|
|
5
|
+
"description": "Mosaic workflows for core file system",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">= 12.0.0"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"clean": "rm -fr dist"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git@github.com:jpmorganchase/mosaic.git"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/uuid": "^8.3.4"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@jpmorganchase/mosaic-serialisers": "^0.1.0-beta.6",
|
|
27
|
+
"@jpmorganchase/mosaic-source-bitbucket": "^0.1.0-beta.6",
|
|
28
|
+
"@jpmorganchase/mosaic-types": "^0.1.0-beta.6",
|
|
29
|
+
"uuid": "^7.0.3"
|
|
30
|
+
}
|
|
31
|
+
}
|