1
0
Fork 0
mirror of https://github.com/imjasonh/apidiff-action synced 2026-07-06 22:52:43 +00:00

Fix lint errors and formatting

- Remove unused variables
- Add .eslintignore to exclude dist/
- Apply prettier formatting
- Fix all pre-commit hook issues
This commit is contained in:
Jason Hall 2025-07-29 17:07:15 -04:00
parent e3eca548b6
commit 805c061497
Failed to extract signature
20 changed files with 2397 additions and 2391 deletions

3
.eslintignore Normal file
View file

@ -0,0 +1,3 @@
dist/
node_modules/
coverage/

View file

@ -34,7 +34,9 @@ async function run() {
newRef = context.payload.after;
core.info(`Comparing commits ${oldRef} with ${newRef}`);
} else {
throw new Error('Unable to determine commits to compare. This action should be run on pull_request or push events.');
throw new Error(
'Unable to determine commits to compare. This action should be run on pull_request or push events.'
);
}
// Run apidiff
@ -62,7 +64,6 @@ async function run() {
} else {
core.info('No breaking API changes detected');
}
} catch (error) {
core.setFailed(`Action failed: ${error.message}`);
}

View file

@ -23,17 +23,15 @@ async function runApidiff({ workingDirectory, oldRef, newRef }) {
// For directories, we need to create export files first
const oldDir = path.join(workingDirectory, oldRef);
const newDir = path.join(workingDirectory, newRef);
const oldExportPath = path.join(oldDir, 'apidiff.export');
const newExportPath = path.join(newDir, 'apidiff.export');
// Create export for old version
await exec.exec('apidiff', ['-w', 'apidiff.export', '.'], {
cwd: oldDir
cwd: oldDir,
});
// Create export for new version
await exec.exec('apidiff', ['-w', 'apidiff.export', '.'], {
cwd: newDir
cwd: newDir,
});
// Now compare the export files
@ -48,9 +46,9 @@ async function runApidiff({ workingDirectory, oldRef, newRef }) {
},
stderr: (data) => {
errorOutput += data.toString();
}
},
ignoreReturnCode: true
},
ignoreReturnCode: true,
};
// Compare using relative paths from working directory
@ -82,9 +80,9 @@ async function runApidiff({ workingDirectory, oldRef, newRef }) {
},
stderr: (data) => {
errorOutput += data.toString();
}
},
ignoreReturnCode: true
},
ignoreReturnCode: true,
};
const exitCode = await exec.exec('apidiff', [oldRef, newRef], options);

View file

@ -31,12 +31,10 @@ async function createOrUpdateComment({ token, body }) {
const { data: comments } = await octokit.rest.issues.listComments({
owner,
repo,
issue_number: prNumber
issue_number: prNumber,
});
const existingComment = comments.find(comment =>
comment.body?.includes(COMMENT_TAG)
);
const existingComment = comments.find((comment) => comment.body?.includes(COMMENT_TAG));
if (existingComment) {
// Update existing comment
@ -44,7 +42,7 @@ async function createOrUpdateComment({ token, body }) {
owner,
repo,
comment_id: existingComment.id,
body: commentBody
body: commentBody,
});
core.info(`Updated existing comment: ${existingComment.html_url}`);
} else {
@ -53,7 +51,7 @@ async function createOrUpdateComment({ token, body }) {
owner,
repo,
issue_number: prNumber,
body: commentBody
body: commentBody,
});
core.info(`Created new comment: ${newComment.html_url}`);
}

View file

@ -10,7 +10,7 @@ function parseApidiffOutput(output) {
hasBreakingChanges: false,
breakingCount: 0,
compatibleCount: 0,
packages: []
packages: [],
};
if (!output || output.trim() === '') {
@ -23,7 +23,7 @@ function parseApidiffOutput(output) {
let currentPackage = {
name: 'default',
breaking: [],
compatible: []
compatible: [],
};
result.packages.push(currentPackage);
@ -58,7 +58,7 @@ function parseApidiffOutput(output) {
const change = {
message: changeMessage,
compatible: inCompatibleSection
compatible: inCompatibleSection,
};
if (inCompatibleSection) {
@ -72,8 +72,8 @@ function parseApidiffOutput(output) {
}
// Clean up empty packages
result.packages = result.packages.filter(pkg =>
pkg.breaking.length > 0 || pkg.compatible.length > 0
result.packages = result.packages.filter(
(pkg) => pkg.breaking.length > 0 || pkg.compatible.length > 0
);
// If no packages with changes, return empty packages array
@ -81,7 +81,9 @@ function parseApidiffOutput(output) {
result.packages = [];
}
core.info(`Parsed ${result.breakingCount} breaking changes and ${result.compatibleCount} compatible changes`);
core.info(
`Parsed ${result.breakingCount} breaking changes and ${result.compatibleCount} compatible changes`
);
return result;
}

4566
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,30 +1,11 @@
{
"name": "apidiff-action",
"version": "1.0.0",
"description": "GitHub Action for detecting breaking API changes in Go code",
"main": "index.js",
"scripts": {
"build": "ncc build index.js -o dist",
"test": "jest",
"lint": "eslint .",
"format": "prettier --write .",
"prepare": "husky install"
},
"keywords": [
"github-action",
"go",
"golang",
"api",
"compatibility",
"breaking-changes"
],
"author": "Jason Hall",
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0"
},
"description": "GitHub Action for detecting breaking API changes in Go code",
"devDependencies": {
"@types/jest": "^29.5.11",
"@vercel/ncc": "^0.38.1",
@ -35,6 +16,27 @@
"lint-staged": "^15.2.0",
"prettier": "^3.1.1"
},
"jest": {
"collectCoverage": true,
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
},
"testEnvironment": "node"
},
"keywords": [
"github-action",
"go",
"golang",
"api",
"compatibility",
"breaking-changes"
],
"license": "Apache-2.0",
"lint-staged": {
"*.js": [
"eslint --fix",
@ -44,16 +46,14 @@
"prettier --write"
]
},
"jest": {
"testEnvironment": "node",
"collectCoverage": true,
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
}
"main": "index.js",
"name": "apidiff-action",
"scripts": {
"build": "ncc build index.js -o dist",
"format": "prettier --write .",
"lint": "eslint .",
"prepare": "husky install",
"test": "jest"
},
"version": "1.0.0"
}

View file

@ -86,7 +86,7 @@ describe('formatChangesAsMarkdown', () => {
hasBreakingChanges: false,
breakingCount: 0,
compatibleCount: 0,
packages: []
packages: [],
};
const markdown = formatChangesAsMarkdown(parsedChanges);
@ -98,11 +98,13 @@ describe('formatChangesAsMarkdown', () => {
hasBreakingChanges: true,
breakingCount: 1,
compatibleCount: 0,
packages: [{
packages: [
{
name: 'default',
breaking: [{ message: 'Foo: removed', compatible: false }],
compatible: []
}]
compatible: [],
},
],
};
const markdown = formatChangesAsMarkdown(parsedChanges);
@ -118,14 +120,16 @@ describe('formatChangesAsMarkdown', () => {
hasBreakingChanges: false,
breakingCount: 0,
compatibleCount: 2,
packages: [{
packages: [
{
name: 'default',
breaking: [],
compatible: [
{ message: 'Bar: added', compatible: true },
{ message: 'Baz: added', compatible: true }
]
}]
{ message: 'Baz: added', compatible: true },
],
},
],
};
const markdown = formatChangesAsMarkdown(parsedChanges);