Skip to content

Commit

Permalink
fix(gerrit): commitBody setting not working
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs committed May 1, 2024
1 parent 8ce089b commit 54f6180
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
15 changes: 9 additions & 6 deletions lib/modules/platform/gerrit/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class GerritClient {
'LABELS',
'CURRENT_ACTIONS', //to check if current_revision can be "rebased"
'CURRENT_REVISION', //get RevisionInfo::ref to fetch
'CURRENT_COMMIT', // to get the commit message
] as const;

private gerritHttp = new GerritHttp();
Expand Down Expand Up @@ -103,15 +104,17 @@ class GerritClient {
});
}

async updateCommitMessage(
async updateChangeSubject(
number: number,
gerritChangeID: string,
prTitle: string,
currentMessage: string,
newSubject: string,
): Promise<void> {
await this.setCommitMessage(
number,
`${prTitle}\n\nChange-Id: ${gerritChangeID}\n`,
// Replace first line of the commit message with the new subject
const newMessage = currentMessage.replace(
new RegExp(`^.*$`, 'm'),
newSubject,
);
await this.setCommitMessage(number, newMessage);
}

async getMessages(changeNumber: number): Promise<GerritChangeMessageInfo[]> {
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/platform/gerrit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ export async function updatePr(prConfig: UpdatePrConfig): Promise<void> {
logger.debug(`updatePr(${prConfig.number}, ${prConfig.prTitle})`);
const change = await client.getChange(prConfig.number);
if (change.subject !== prConfig.prTitle) {
await client.updateCommitMessage(
await client.updateChangeSubject(
prConfig.number,
change.change_id,
change.revisions[change.current_revision].commit.message,
prConfig.prTitle,
);
}
Expand Down Expand Up @@ -200,9 +200,9 @@ export async function createPr(prConfig: CreatePRConfig): Promise<Pr | null> {
}
//Workaround for "Known Problems.1"
if (pr.subject !== prConfig.prTitle) {
await client.updateCommitMessage(
await client.updateChangeSubject(
pr._number,
pr.change_id,
pr.revisions[pr.current_revision].commit.message,
prConfig.prTitle,
);
}
Expand Down
9 changes: 7 additions & 2 deletions lib/modules/platform/gerrit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,26 @@ export interface GerritChange {
labels?: Record<string, GerritLabelInfo>;
reviewers?: Record<GerritReviewersType, GerritAccountInfo[]>;
messages?: GerritChangeMessageInfo[];
current_revision?: string;
current_revision: string;
/**
* All patch sets of this change as a map that maps the commit ID of the patch set to a RevisionInfo entity.
*/
revisions?: Record<string, GerritRevisionInfo>;
revisions: Record<string, GerritRevisionInfo>;
problems: unknown[];
}

export interface GerritCommitInfo {
message: string;
}

export interface GerritRevisionInfo {
uploader: GerritAccountInfo;
/**
* The Git reference for the patch set.
*/
ref: string;
actions?: Record<string, GerritActionInfo>;
commit: GerritCommitInfo;
}

export interface GerritChangeMessageInfo {
Expand Down

0 comments on commit 54f6180

Please sign in to comment.