@jpmorganchase/mosaic-workflows 0.1.0-beta.10
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,64 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { Repo } from '@jpmorganchase/mosaic-source-git-repo';
|
|
5
|
+
import { mdx } from '@jpmorganchase/mosaic-serialisers';
|
|
6
|
+
let repoInstance = null;
|
|
7
|
+
async function createPullRequest(sourceOptions, { apiEndpoint, commitMessage, titlePrefix }, filePath, { user, markdown }) {
|
|
8
|
+
const { credentials, remote, branch: sourceBranch, repo: repoUrl, subfolder, prefixDir } = sourceOptions;
|
|
9
|
+
if (!repoUrl || !markdown) {
|
|
10
|
+
// indicate to the plugin runner that no save happened
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (!repoInstance) {
|
|
14
|
+
repoInstance = new Repo(credentials, remote, sourceBranch, repoUrl);
|
|
15
|
+
await repoInstance.init();
|
|
16
|
+
}
|
|
17
|
+
const branchName = `${user.sid.toLowerCase()}-${uuidv4()}`;
|
|
18
|
+
await repoInstance.createWorktree(user.sid.toLowerCase(), branchName);
|
|
19
|
+
/**
|
|
20
|
+
* strip out the namespace from the file path.
|
|
21
|
+
* We are interested in the file on disk not in the VFS
|
|
22
|
+
*/
|
|
23
|
+
const pathOnDisk = path.posix.join(repoInstance.dir, subfolder, filePath.replace(new RegExp(`${prefixDir}/`), ''));
|
|
24
|
+
const rawPage = await fs.promises.readFile(pathOnDisk);
|
|
25
|
+
const { content, ...metadata } = await mdx.deserialise(pathOnDisk, rawPage);
|
|
26
|
+
const updatedPage = { ...metadata, content: markdown };
|
|
27
|
+
await fs.promises.writeFile(pathOnDisk, await mdx.serialise(pathOnDisk, updatedPage));
|
|
28
|
+
const bitBucketRequest = JSON.stringify({
|
|
29
|
+
title: `${titlePrefix} - Content update - ${filePath}`,
|
|
30
|
+
fromRef: {
|
|
31
|
+
id: `refs/heads/${branchName}`,
|
|
32
|
+
repository: {
|
|
33
|
+
slug: `${repoInstance.repoName}`,
|
|
34
|
+
name: null,
|
|
35
|
+
project: {
|
|
36
|
+
key: `${repoInstance.projectName}`
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
toRef: {
|
|
41
|
+
id: `refs/heads/${sourceBranch}`,
|
|
42
|
+
repository: {
|
|
43
|
+
slug: `${repoInstance.repoName}`,
|
|
44
|
+
name: null,
|
|
45
|
+
project: {
|
|
46
|
+
key: `${repoInstance.projectName}`
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const endpoint = `${apiEndpoint}/projects/${repoInstance.projectName}/repos/${repoInstance.repoName}/pull-requests`;
|
|
52
|
+
return repoInstance.createPullRequest(user, branchName, filePath, endpoint, bitBucketRequest, commitMessage(filePath));
|
|
53
|
+
}
|
|
54
|
+
const workflow = {
|
|
55
|
+
name: 'save',
|
|
56
|
+
options: {
|
|
57
|
+
titlePrefix: 'Mosaic Docs',
|
|
58
|
+
apiEndpoint: process.env.BITBUCKET_API_URL || '',
|
|
59
|
+
commitMessage: (filePath) => `docs: updated content ${filePath} (UIE-7026)`
|
|
60
|
+
},
|
|
61
|
+
action: createPullRequest
|
|
62
|
+
};
|
|
63
|
+
export default workflow;
|
|
64
|
+
//# sourceMappingURL=BitBucketPullRequestWorkflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitBucketPullRequestWorkflow.js","sourceRoot":"","sources":["../src/BitBucketPullRequestWorkflow.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,IAAI,EAAwB,M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B,EAAE,EAAE,CAAC,yBAAyB,QAAQ,aAAa;KACpF;IACD,MAAM,EAAE,iBAAiB;CAC1B,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E,OAAO,EAAE,4BAA4B,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jpmorganchase/mosaic-workflows",
|
|
3
|
+
"version": "0.1.0-beta.10",
|
|
4
|
+
"description": "Mosaic workflows for core file system",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"node": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">= 16.0.0"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"clean": "rm -fr dist",
|
|
25
|
+
"lint": "eslint --ignore-pattern \"**/__tests__/**\""
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git@github.com:jpmorganchase/mosaic.git"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/uuid": "^8.3.4"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@jpmorganchase/mosaic-serialisers": "^0.1.0-beta.10",
|
|
36
|
+
"@jpmorganchase/mosaic-source-git-repo": "^0.1.0-beta.10",
|
|
37
|
+
"@jpmorganchase/mosaic-types": "^0.1.0-beta.10",
|
|
38
|
+
"uuid": "^7.0.3"
|
|
39
|
+
}
|
|
40
|
+
}
|