Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

add netlify sdk v0.8.1 codemods #358

Merged
merged 11 commits into from
Sep 22, 2023
Merged
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: 59 additions & 0 deletions netlify-sdk/0.8.1/addBuildEventContext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Rename addBuildEventContext

## Description

This codemod renames `addBuildContext` to `addBuildEventContext` as required in Netlify SDK v0.8.1.

## Example

### Before

```jsx
import { NetlifyIntegration } from '@netlify/sdk';

const integration = new NetlifyIntegration();

// Adding a build event handler
integration.addBuildContext(() => {});
```

### After

```jsx
import { NetlifyIntegration } from '@netlify/sdk';

const integration = new NetlifyIntegration();

// Adding a build event handler
integration.addBuildEventContext(() => {});
```

## Applicability Criteria

Netlify SDK v0.8.1 or higher.

## Other Metadata

### Codemod Version

v1.0.0

### Change Mode

**Autonomous**: Changes can safely be pushed and merged without further human involvement.

### **Codemod Engine**

jscodeshift

### Estimated Time Saving

~1 minutes per occurrence

### Owner

[Intuita](https://github.com/intuita-inc)

### Links for more info

- [Netlify SDK v0.8.1 Release Notes](https://sdk.netlify.com/release-notes/#081)
5 changes: 5 additions & 0 deletions netlify-sdk/0.8.1/addBuildEventContext/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"schemaVersion": "1.0.0",
"name": "netlify/0.8.1/addBuildEventContext",
"engine": "jscodeshift"
}
29 changes: 29 additions & 0 deletions netlify-sdk/0.8.1/addBuildEventContext/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { FileInfo, API, Options } from 'jscodeshift';
export default function transform(
file: FileInfo,
api: API,
options: Options,

Check failure on line 5 in netlify-sdk/0.8.1/addBuildEventContext/index.ts

View workflow job for this annotation

GitHub Actions / Run codemod unit tests

'options' is defined but never used
): string | undefined {
const j = api.jscodeshift;
const root = j(file.source);

// Find all CallExpressions
root.find(j.CallExpression).forEach((path) => {
// Ensure the callee is a MemberExpression
if (path.node.callee.type === 'MemberExpression') {
// Ensure the object is an Identifier named 'integration'
if (path.node.callee.object.type === 'Identifier') {
// Ensure the property is an Identifier named 'addBuildContext'
if (
path.node.callee.property.type === 'Identifier' &&
path.node.callee.property.name === 'addBuildContext'
) {
// Replace 'addBuildContext' with 'addBuildEventContext'
path.node.callee.property.name = 'addBuildEventContext';
}
}
}
});

return root.toSource();
}
32 changes: 32 additions & 0 deletions netlify-sdk/0.8.1/addBuildEventContext/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { FileInfo } from 'jscodeshift';
import assert from 'node:assert';
import transform from './index.js';
import { buildApi } from '../../../utilities.js';

describe('netlify 0.8.1 addBuildEventContext', function () {
it('changes addBuildContext to addBuildEventContext', function () {
const INPUT = `
integration.addBuildContext("onPreBuild", () => {
//FOO
});
`;

const OUTPUT = `
integration.addBuildEventContext("onPreBuild", () => {
//FOO
});
`;

const fileInfo: FileInfo = {
path: 'index.js',
source: INPUT,
};

const actualOutput = transform(fileInfo, buildApi('tsx'));

assert.deepEqual(
actualOutput?.replace(/\W/gm, ''),
OUTPUT.replace(/\W/gm, ''),
);
});
});
63 changes: 63 additions & 0 deletions netlify-sdk/0.8.1/addBuildEventHandler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Rename addBuildEventHandler

## Description

This codemod renames `addBuildHook` to `addBuildEventHandler` as required in Netlify SDK v0.8.1.

## Example

### Before

```jsx
import { NetlifyIntegration } from '@netlify/sdk';

const integration = new NetlifyIntegration();

// Adding a build event handler
integration.addBuildHook('onPreBuild', () => {
console.log('This is my first build event handler!');
});
```

### After

```jsx
import { NetlifyIntegration } from '@netlify/sdk';

const integration = new NetlifyIntegration();

// Adding a build event handler
integration.addBuildEventHandler('onPreBuild', () => {
console.log('This is my first build event handler!');
});
```

## Applicability Criteria

Netlify SDK v0.8.1 or higher.

## Other Metadata

### Codemod Version

v1.0.0

### Change Mode

**Autonomous**: Changes can safely be pushed and merged without further human involvement.

### **Codemod Engine**

jscodeshift

### Estimated Time Saving

~1 minutes per occurrence

### Owner

[Intuita](https://github.com/intuita-inc)

### Links for more info

- [Netlify SDK v0.8.1 Release Notes](https://sdk.netlify.com/release-notes/#081)
5 changes: 5 additions & 0 deletions netlify-sdk/0.8.1/addBuildEventHandler/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"schemaVersion": "1.0.0",
"name": "netlify/0.8.1/addBuildEventHandler",
"engine": "jscodeshift"
}
32 changes: 32 additions & 0 deletions netlify-sdk/0.8.1/addBuildEventHandler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { FileInfo, API, Options } from 'jscodeshift';
export default function transform(
file: FileInfo,
api: API,
options: Options,

Check failure on line 5 in netlify-sdk/0.8.1/addBuildEventHandler/index.ts

View workflow job for this annotation

GitHub Actions / Run codemod unit tests

'options' is defined but never used
): string | undefined {
const j = api.jscodeshift;
const root = j(file.source);

// Find all CallExpressions
root.find(j.CallExpression).forEach((path) => {
// Ensure the callee is a MemberExpression
if (path.node.callee.type === 'MemberExpression') {
// Ensure the object is an Identifier named 'integration'
if (
path.node.callee.object.type === 'Identifier' &&
path.node.callee.object.name === 'integration'
) {
// Ensure the property is an Identifier named 'addBuildHook'
if (
path.node.callee.property.type === 'Identifier' &&
path.node.callee.property.name === 'addBuildHook'
) {
// Replace 'addBuildHook' with 'addBuildEventHandler'
path.node.callee.property.name = 'addBuildEventHandler';
}
}
}
});

return root.toSource();
}
28 changes: 28 additions & 0 deletions netlify-sdk/0.8.1/addBuildEventHandler/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FileInfo } from 'jscodeshift';
import assert from 'node:assert';
import transform from './index.js';
import { buildApi } from '../../../utilities.js';

describe('netlify 0.8.1 addBuildEventContext', function () {
it('changes addBuildHook to addBuildEventContext', function () {
const INPUT = `
integration.addBuildHook("onPreBuild", () => {});
`;

const OUTPUT = `
integration.addBuildEventHandler("onPreBuild", () => {});
`;

const fileInfo: FileInfo = {
path: 'index.js',
source: INPUT,
};

const actualOutput = transform(fileInfo, buildApi('tsx'));

assert.deepEqual(
actualOutput?.replace(/\W/gm, ''),
OUTPUT.replace(/\W/gm, ''),
);
});
});
49 changes: 49 additions & 0 deletions netlify-sdk/0.8.1/disableBuildEventHandlers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Rename disableBuildEventHandlers

## Description

This codemod renames `disableBuildhook` to `disableBuildEventHandlers` as required in Netlify SDK v0.8.1.

## Example

### Before

```jsx
await client.disableBuildhook(siteId);
```

### After

```jsx
await client.disableBuildEventHandlers(siteId);
```

## Applicability Criteria

Netlify SDK v0.8.1 or higher.

## Other Metadata

### Codemod Version

v1.0.0

### Change Mode

**Autonomous**: Changes can safely be pushed and merged without further human involvement.

### **Codemod Engine**

jscodeshift

### Estimated Time Saving

~1 minutes per occurrence

### Owner

[Intuita](https://github.com/intuita-inc)

### Links for more info

- [Netlify SDK v0.8.1 Release Notes](https://sdk.netlify.com/release-notes/#081)
5 changes: 5 additions & 0 deletions netlify-sdk/0.8.1/disableBuildEventHandlers/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"schemaVersion": "1.0.0",
"name": "netlify/0.8.1/disableBuildEventHandlers",
"engine": "jscodeshift"
}
31 changes: 31 additions & 0 deletions netlify-sdk/0.8.1/disableBuildEventHandlers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { FileInfo, API, Options } from 'jscodeshift';
export default function transform(
file: FileInfo,
api: API,
options: Options,

Check failure on line 5 in netlify-sdk/0.8.1/disableBuildEventHandlers/index.ts

View workflow job for this annotation

GitHub Actions / Run codemod unit tests

'options' is defined but never used
): string | undefined {
const j = api.jscodeshift;
const root = j(file.source);

// Find all CallExpressions
root.find(j.CallExpression).forEach((path) => {
// Ensure the callee is a MemberExpression
if (path.node.callee.type === 'MemberExpression') {
const memberExpression = path.node.callee;
// Ensure the object is an Identifier named 'client'
if (memberExpression.object.type === 'Identifier') {
// Ensure the property is an Identifier named 'disableBuildhook'
if (
memberExpression.property.type === 'Identifier' &&
memberExpression.property.name === 'disableBuildhook'
) {
// Replace 'disableBuildhook' with 'disableBuildEventHandlers'
memberExpression.property.name =
'disableBuildEventHandlers';
}
}
}
});

return root.toSource();
}
28 changes: 28 additions & 0 deletions netlify-sdk/0.8.1/disableBuildEventHandlers/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FileInfo } from 'jscodeshift';
import assert from 'node:assert';
import transform from './index.js';
import { buildApi } from '../../../utilities.js';

describe('netlify 0.8.1 disableBuildEventHandlers', function () {
it('changes disableBuildhook to disableBuildEventHandlers', function () {
const INPUT = `
await client.disableBuildhook(siteId);
`;

const OUTPUT = `
await client.disableBuildEventHandlers(siteId);
`;

const fileInfo: FileInfo = {
path: 'index.js',
source: INPUT,
};

const actualOutput = transform(fileInfo, buildApi('tsx'));

assert.deepEqual(
actualOutput?.replace(/\W/gm, ''),
OUTPUT.replace(/\W/gm, ''),
);
});
});
Loading
Loading