Skip to content

Commit 33bacb1

Browse files
committed
Add firstPatchLine to IMailMetadata
Track the first patch line from patch email so it can be used on the commit comment. Signed-off-by: Chris. Webster <chris@webstech.net>
1 parent 776afad commit 33bacb1

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

lib/github-glue.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,13 @@ export class GitHubGlue {
190190
* @param {pullRequestKeyInfo} pullRequest - the Pull Request to comment on
191191
* @param {string} commit the hash of the commit to comment on
192192
* @param {string} comment the comment
193+
* @param {number} line the comment is referencing
193194
* @returns the comment ID and the URL to the comment
194195
*/
195196
public async addPRCommitComment(pullRequest: pullRequestKeyInfo,
196197
commit: string,
197198
gitWorkDir: string | undefined,
198-
comment: string):
199+
comment: string, line?: number | undefined):
199200
Promise<{id: number; url: string}> {
200201
const prKey = getPullRequestKey(pullRequest);
201202

@@ -210,7 +211,7 @@ export class GitHubGlue {
210211
body: comment,
211212
commit_id: commit,
212213
path,
213-
line: 1,
214+
line: line || 1,
214215
...prKey
215216
});
216217
return {

lib/mail-archive-helper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class MailArchiveGitHelper {
145145
let pullRequestURL: string | undefined;
146146
let originalCommit: string | undefined;
147147
let issueCommentId: number | undefined;
148+
let firstPatchLine: number | undefined;
148149
for (const reference of parsed.references.filter(seen)) {
149150
const data = await this.gggNotes.get<IMailMetadata>(reference);
150151
if (data && data.pullRequestURL) {
@@ -157,6 +158,7 @@ export class MailArchiveGitHelper {
157158
(!issueCommentId && data.issueCommentId)) {
158159
pullRequestURL = data.pullRequestURL;
159160
issueCommentId = data.issueCommentId;
161+
firstPatchLine = data.firstPatchLine;
160162
originalCommit = commit;
161163
}
162164
}
@@ -182,7 +184,7 @@ export class MailArchiveGitHelper {
182184
} else if (originalCommit) {
183185
try {
184186
const result = await this.githubGlue.addPRCommitComment(pullRequestURL, originalCommit,
185-
this.gggNotes.workDir, fullComment);
187+
this.gggNotes.workDir, fullComment, firstPatchLine);
186188
issueCommentId = result.id;
187189
} catch (error) {
188190
const regarding = `${header.slice(0,-3)}, regarding ${originalCommit}:\n\n`;

lib/mail-metadata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface IMailMetadata {
44
issueCommentId?: number;
55
originalCommit?: string;
66
commitInGitGit?: string;
7+
firstPatchLine?: number;
78
}

lib/patch-series.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,20 +823,26 @@ export class PatchSeries {
823823
const messageID = mail.match(/\nMessage-ID: <(.*?)>\n/i);
824824
if (messageID) {
825825
let originalCommit: string | undefined;
826+
let firstPatchLine: number | undefined;
826827
if (isCoverLetter) {
827828
isCoverLetter = false;
828829
} else {
829830
const commitMatch = mail.match(/^From ([0-9a-f]{40}) /);
830831
if (commitMatch) {
831832
originalCommit = commitMatch[1];
832833
}
834+
const revLine = mail.match(/\n@@ -(\d+),/);
835+
if (revLine) {
836+
firstPatchLine = parseInt(revLine[1], 10);
837+
}
833838
}
834839

835840
const mid = messageID[1];
836841
const mailMeta = {
837842
messageID: mid,
838843
originalCommit,
839844
pullRequestURL: this.metadata.pullRequestURL,
845+
firstPatchLine
840846
} as IMailMetadata;
841847
await this.notes.set(mid, mailMeta, true);
842848
if (globalOptions && originalCommit &&

0 commit comments

Comments
 (0)