@jpmorganchase/mosaic-workflows 0.0.0-snapshot-20240604074928

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,3 @@
1
+ import type { SourceWorkflow } from '@jpmorganchase/mosaic-types';
2
+ declare const workflow: SourceWorkflow;
3
+ export default workflow;
@@ -0,0 +1,69 @@
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
+ async function createPullRequest(sendWorkflowProgressMessage, sourceOptions, { apiEndpoint, commitMessage, titlePrefix }, filePath, { user, markdown }) {
7
+ const { credentials, remote, branch: sourceBranch, repo: repoUrl, subfolder, prefixDir } = sourceOptions;
8
+ if (!repoUrl || !markdown) {
9
+ // indicate to the plugin runner that no save happened
10
+ return false;
11
+ }
12
+ let repoInstance = new Repo(credentials, remote, sourceBranch, repoUrl);
13
+ await repoInstance.init();
14
+ sendWorkflowProgressMessage('Bitbucket clone complete', 'IN_PROGRESS');
15
+ const branchName = `${user.sid.toLowerCase()}-${uuidv4()}`;
16
+ await repoInstance.createWorktree(user.sid.toLowerCase(), branchName);
17
+ sendWorkflowProgressMessage('Created git worktree', 'IN_PROGRESS');
18
+ /**
19
+ * strip out the namespace from the file path.
20
+ * We are interested in the file on disk not in the VFS
21
+ */
22
+ const pathOnDisk = path.posix.join(repoInstance.dir, subfolder, filePath.replace(new RegExp(`${prefixDir}/`), ''));
23
+ const rawPage = await fs.promises.readFile(pathOnDisk);
24
+ const { content, ...metadata } = await mdx.deserialise(pathOnDisk, rawPage);
25
+ const updatedPage = { ...metadata, content: markdown };
26
+ sendWorkflowProgressMessage('Updated page content', 'IN_PROGRESS');
27
+ await fs.promises.writeFile(pathOnDisk, await mdx.serialise(pathOnDisk, updatedPage));
28
+ sendWorkflowProgressMessage('Saved page', 'IN_PROGRESS');
29
+ const bitBucketRequest = JSON.stringify({
30
+ title: `${titlePrefix} - Content update - ${filePath}`,
31
+ fromRef: {
32
+ id: `refs/heads/${branchName}`,
33
+ repository: {
34
+ slug: `${repoInstance.repoName}`,
35
+ name: null,
36
+ project: {
37
+ key: `${repoInstance.projectName}`
38
+ }
39
+ }
40
+ },
41
+ toRef: {
42
+ id: `refs/heads/${sourceBranch}`,
43
+ repository: {
44
+ slug: `${repoInstance.repoName}`,
45
+ name: null,
46
+ project: {
47
+ key: `${repoInstance.projectName}`
48
+ }
49
+ }
50
+ }
51
+ });
52
+ const endpoint = `${apiEndpoint}/projects/${repoInstance.projectName}/repos/${repoInstance.repoName}/pull-requests`;
53
+ sendWorkflowProgressMessage('Creating Pull Request', 'IN_PROGRESS');
54
+ const result = await repoInstance.createPullRequest(user, branchName, filePath, endpoint, bitBucketRequest, commitMessage(filePath));
55
+ sendWorkflowProgressMessage(result, 'COMPLETE');
56
+ repoInstance = null;
57
+ return result;
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
+ export default workflow;
69
+ //# 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,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,GAAG,EAAE,MAAM,mCAAmC,CAAC;AAcxD,KAAK,UAAU,iBAAiB,CAC9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AAI,CAAC;IACpB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,QAAQ,GAAmB;IAC/B,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,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import BitbucketPullRequestWorkflow from './BitbucketPullRequestWorkflow.js';
2
+ export { BitbucketPullRequestWorkflow };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import BitbucketPullRequestWorkflow from './BitbucketPullRequestWorkflow.js';
2
+ export { BitbucketPullRequestWorkflow };
3
+ //# sourceMappingURL=index.js.map
@@ -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,42 @@
1
+ {
2
+ "name": "@jpmorganchase/mosaic-workflows",
3
+ "version": "0.0.0-snapshot-20240604074928",
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
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "engines": {
18
+ "node": ">=16.10.0 || >=18.0.0"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "clean": "rm -fr dist",
26
+ "lint": "eslint --ignore-pattern \"**/__tests__/**\""
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git@github.com:jpmorganchase/mosaic.git",
31
+ "directory": "packages/workflows"
32
+ },
33
+ "devDependencies": {
34
+ "@types/uuid": "^8.3.4"
35
+ },
36
+ "dependencies": {
37
+ "@jpmorganchase/mosaic-serialisers": "0.0.0-snapshot-20240604074928",
38
+ "@jpmorganchase/mosaic-source-git-repo": "0.0.0-snapshot-20240604074928",
39
+ "@jpmorganchase/mosaic-types": "0.0.0-snapshot-20240604074928",
40
+ "uuid": "^7.0.3"
41
+ }
42
+ }