Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOP-5031]: Add persistence module functionality to script #9

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.1/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false,
"ignore": ["*/.ntli/*"]
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingCommas": "all"
}
}
"$schema": "https://biomejs.dev/schemas/1.9.1/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false,
"ignore": ["*/.ntli/*", "*/node_modules/*"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingCommas": "all"
}
}
}
42 changes: 21 additions & 21 deletions git-changed-files/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "git-changed-files",
"version": "0.0.1",
"main": "src/index.ts",
"type": "module",
"scripts": {
"build": "netlify-integration build -a",
"dev": "netlify-integration dev -a",
"preview": "netlify-integration preview",
"test": "vitest"
},
"dependencies": {
"@netlify/sdk": "^1.60.2-pr-1468.3",
"axios": "^1.7.7",
"typescript": "^5.4.5"
},
"devDependencies": {
"@netlify/build": "^29.50.2",
"@types/node": "^20.14.9",
"execa": "^6.1.0",
"vitest": "^2.1.0"
}
"name": "git-changed-files",
"version": "0.0.1",
"main": "src/index.ts",
"type": "module",
"scripts": {
"build": "netlify-integration build -a",
"dev": "netlify-integration dev -a",
"preview": "netlify-integration preview",
"test": "vitest"
},
"dependencies": {
"@netlify/sdk": "^1.60.2-pr-1468.3",
"axios": "^1.7.7",
"typescript": "^5.4.5"
},
"devDependencies": {
"@netlify/build": "^29.50.2",
"@types/node": "^20.14.9",
"execa": "^6.1.0",
"vitest": "^2.1.0"
}
}
70 changes: 35 additions & 35 deletions git-changed-files/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { NetlifyIntegration } from '@netlify/sdk';
const integration = new NetlifyIntegration();

integration.addBuildEventHandler('onSuccess', ({ utils: { status, git } }) => {
console.log('Checking if any files changed on git -----');
console.log('Modified files:', git.modifiedFiles);

if (!process.env.DEPLOY_PRIME_URL) {
console.error('ERROR! process.env.DEPLOY_PRIME_URL is not defined.');
return;
}

const markdownList = createMarkdown(
git.modifiedFiles,
process.env.DEPLOY_PRIME_URL,
);

if (markdownList.length !== 0) {
status.show({
title: `URLs to Changed Files`,
summary: markdownList.join('\n'),
});
}
console.log('Checking if any files changed on git -----');
console.log('Modified files:', git.modifiedFiles);

if (!process.env.DEPLOY_PRIME_URL) {
console.error('ERROR! process.env.DEPLOY_PRIME_URL is not defined.');
return;
}

const markdownList = createMarkdown(
git.modifiedFiles,
process.env.DEPLOY_PRIME_URL,
);

if (markdownList.length !== 0) {
status.show({
title: 'URLs to Changed Files',
summary: markdownList.join('\n'),
});
}
});

/**
Expand All @@ -33,28 +33,28 @@ integration.addBuildEventHandler('onSuccess', ({ utils: { status, git } }) => {
* @returns string[]
*/
export function createMarkdown(
modifiedFiles: readonly string[],
netlifyURL: string,
modifiedFiles: readonly string[],
netlifyURL: string,
): string[] {
const IGNORED_DIRS = new Set(['includes', 'images', 'examples']);
const IGNORED_DIRS = new Set(['includes', 'images', 'examples']);

const markdownList = [];
for (const modifiedFile of modifiedFiles) {
const modifiedFilePath = modifiedFile.split('/');
const markdownList = [];
for (const modifiedFile of modifiedFiles) {
const modifiedFilePath = modifiedFile.split('/');

// check if this is equal to 'source'
const isSourceDir = modifiedFilePath[0] === 'source';
// check if this is equal to 'source'
const isSourceDir = modifiedFilePath[0] === 'source';

// check if this is equal to either images, includes, or examples
const isNonIgnoredDir = !IGNORED_DIRS.has(modifiedFilePath[1]);
// check if this is equal to either images, includes, or examples
const isNonIgnoredDir = !IGNORED_DIRS.has(modifiedFilePath[1]);

if (isSourceDir && isNonIgnoredDir) {
const shortform = modifiedFile.replace('source', '').replace('.txt', '');
markdownList.push(`[${modifiedFile}](${netlifyURL + shortform})`);
}
}
if (isSourceDir && isNonIgnoredDir) {
const shortform = modifiedFile.replace('source', '').replace('.txt', '');
markdownList.push(`[${modifiedFile}](${netlifyURL + shortform})`);
}
}

return markdownList;
return markdownList;
}

export { integration };
60 changes: 30 additions & 30 deletions git-changed-files/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ import { expect, test, describe } from 'vitest';
import { createMarkdown } from '../src/index';

describe('Test displaying URLs for changed files in source directory ', () => {
test('It displays files only changed in source', () => {
const exampleModifiedFiles = [
'source/legacy.txt',
'source/trial.txt',
'new.html',
];
const netlifyURL = 'testing.com';
const output = [
'[source/legacy.txt](testing.com/legacy)',
'[source/trial.txt](testing.com/trial)',
];
test('It displays files only changed in source', () => {
const exampleModifiedFiles = [
'source/legacy.txt',
'source/trial.txt',
'new.html',
];
const netlifyURL = 'testing.com';
const output = [
'[source/legacy.txt](testing.com/legacy)',
'[source/trial.txt](testing.com/trial)',
];

expect(createMarkdown(exampleModifiedFiles, netlifyURL)).toStrictEqual(
output,
);
});
expect(createMarkdown(exampleModifiedFiles, netlifyURL)).toStrictEqual(
output,
);
});

test('Test displaying URLs for changed files in source directory except for images', () => {
const exampleModifiedFiles = [
'source/legacy.txt',
'source/trial.txt',
'source/images/picture.png',
];
const netlifyURL = 'testing.com';
const output = [
'[source/legacy.txt](testing.com/legacy)',
'[source/trial.txt](testing.com/trial)',
];
test('Test displaying URLs for changed files in source directory except for images', () => {
const exampleModifiedFiles = [
'source/legacy.txt',
'source/trial.txt',
'source/images/picture.png',
];
const netlifyURL = 'testing.com';
const output = [
'[source/legacy.txt](testing.com/legacy)',
'[source/trial.txt](testing.com/trial)',
];

expect(createMarkdown(exampleModifiedFiles, netlifyURL)).toStrictEqual(
output,
);
});
expect(createMarkdown(exampleModifiedFiles, netlifyURL)).toStrictEqual(
output,
);
});
});
16 changes: 8 additions & 8 deletions git-changed-files/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "bundler",
"strict": true,
"rootDir": "."
},
"exclude": ["node_modules", "dist"]
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "bundler",
"strict": true,
"rootDir": "."
},
"exclude": ["node_modules", "dist"]
}
8 changes: 4 additions & 4 deletions git-changed-files/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
name: 'test-suite',
root: './tests',
},
test: {
name: 'test-suite',
root: './tests',
},
});
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "netlify-integrations",
"description": "",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "biome ci"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@biomejs/biome": "1.9.1"
}
"name": "netlify-integrations",
"description": "",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "biome ci"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@biomejs/biome": "1.9.1"
}
}
28 changes: 14 additions & 14 deletions persistence-module/.netlify/functions/manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"functions": [
{
"bundler": "esbuild",
"buildData": { "runtimeAPIVersion": 1 },
"mainFile": "/Users/brandonly/Documents/gitrepos/chatbot-netlify-integration/.ntli/site/netlify/functions/handler.js",
"name": "handler",
"priority": 10,
"path": "/Users/brandonly/Documents/gitrepos/chatbot-netlify-integration/.netlify/functions/handler.zip",
"runtime": "js"
}
],
"system": { "arch": "arm64", "platform": "darwin" },
"timestamp": 1719950065771,
"version": 1
"functions": [
{
"bundler": "esbuild",
"buildData": { "runtimeAPIVersion": 1 },
"mainFile": "/Users/brandonly/Documents/gitrepos/chatbot-netlify-integration/.ntli/site/netlify/functions/handler.js",
"name": "handler",
"priority": 10,
"path": "/Users/brandonly/Documents/gitrepos/chatbot-netlify-integration/.netlify/functions/handler.zip",
"runtime": "js"
}
],
"system": { "arch": "arm64", "platform": "darwin" },
"timestamp": 1719950065771,
"version": 1
}
2 changes: 1 addition & 1 deletion persistence-module/.netlify/state.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"siteId": "956d0b2c-d0f1-4c7e-bd4c-f27c0542b80f"
"siteId": "956d0b2c-d0f1-4c7e-bd4c-f27c0542b80f"
}
28 changes: 14 additions & 14 deletions persistence-module/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/src/index.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
}
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/src/index.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
}
]
}
Loading
Loading