Skip to content

Commit ddcd40b

Browse files
feat: add diff ID support for PR file links
- Add SHA256 hash generation for file paths - Update PR comment links to use proper diff anchors - Add tests for the new functionality - Update package version to 3.1.3
1 parent bebfaeb commit ddcd40b

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
# Changelog
44

5+
## [3.1.3] - 2026-01-14
6+
7+
### Fixed
8+
9+
- Fixed PR file links to use proper diff anchors instead of file path URLs,
10+
keeping users in PR context navigation
11+
512
## [3.1.2] - 2026-01-14
613

714
### Fixed

__tests__/main.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,17 @@ at Tests.Registration.main(Registration.java:202)`,
679679
});
680680
});
681681

682+
describe('getDiffId', () => {
683+
it('should generate SHA256 hash for file path', () => {
684+
expect(main.getDiffId('src/index.js')).toBe(
685+
'bfe9874d239014961b1ae4e89875a6155667db834a410aaaa2ebe3cf89820556',
686+
);
687+
expect(main.getDiffId('src/modules/products/dto/product.dto.ts')).toBe(
688+
'58d7002fa09097d6e54eec04b3ba865011f947ebb601513ede5829785248e69f',
689+
);
690+
});
691+
});
692+
682693
describe('generateAnnotationSection', () => {
683694
it('should return empty string for no annotations', () => {
684695
expect(
@@ -707,7 +718,7 @@ at Tests.Registration.main(Registration.java:202)`,
707718
'[.../modules/products/dto/product.dto.ts#L167]',
708719
);
709720
expect(result).toContain(
710-
'(https://github.com/owner/repo/pull/123/files/src/modules/products/dto/product.dto.ts#L167)',
721+
'(https://github.com/owner/repo/pull/123/files#diff-58d7002fa09097d6e54eec04b3ba865011f947ebb601513ede5829785248e69f)',
711722
);
712723
});
713724

dist/index.js

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "report-annotate",
33
"description": "Annotate PR from report e.g. junit",
4-
"version": "3.1.2",
4+
"version": "3.1.3",
55
"author": "",
66
"type": "module",
77
"private": true,

src/main.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
22
import * as github from '@actions/github';
33
import { existsSync } from 'node:fs';
44
import { readFile } from 'node:fs/promises';
5+
import { createHash } from 'node:crypto';
56
import { parse } from 'yaml';
67
import { glob } from 'glob';
78
import { junitEslintMatcher } from './matchers/junit-eslint.js';
@@ -379,6 +380,11 @@ export function truncateFilePath(filePath: string): string {
379380
return '...' + '/' + parts.slice(-4).join('/');
380381
}
381382

383+
/** Generate the diff ID for a file path in GitHub PR files view. */
384+
export function getDiffId(filePath: string): string {
385+
return createHash('sha256').update(filePath).digest('hex');
386+
}
387+
382388
/** Generate a comment section for a specific annotation level. */
383389
export function generateAnnotationSection(
384390
levelName: string,
@@ -394,8 +400,8 @@ export function generateAnnotationSection(
394400
let line = `> ${message}`;
395401
if (annotation.properties.file && annotation.properties.startLine) {
396402
const displayLocation = `${truncateFilePath(annotation.properties.file)}#L${annotation.properties.startLine}`;
397-
const linkLocation = `${annotation.properties.file}#L${annotation.properties.startLine}`;
398-
const link = `${baseUrl}/${linkLocation}`;
403+
const diffId = getDiffId(annotation.properties.file);
404+
const link = `${baseUrl}#diff-${diffId}`;
399405
line = `> [${displayLocation}](${link}) ${message}`;
400406
}
401407
section += `${line}\n`;

0 commit comments

Comments
 (0)