Skip to content

Commit

Permalink
add feature to show commit url in the MR title
Browse files Browse the repository at this point in the history
  • Loading branch information
weikangchia committed Aug 5, 2021
1 parent a66f00f commit 730afec
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/changelogGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ChangelogGenerator {

mergeRequestSections[section].forEach((mergeRequestTitle) => {
mergeRequestsContent = mergeRequestsContent.concat(`- ${mergeRequestTitle}`);

mergeRequestsContent = mergeRequestsContent.concat(
this.generateExternalIssuesSectionIfEnabled(mergeRequestTitle),
);
Expand Down Expand Up @@ -86,7 +87,15 @@ class ChangelogGenerator {

mergeRequests.forEach((mergeRequest) => {
if (section.labels.some((label) => mergeRequest.labels.includes(label))) {
mergeRequestSections[section.title].push(mergeRequest.title);
let title = mergeRequest.title;

if (this.#config.enableCommitSha) {
title = title.concat(
` (${this.#gitService.getCommitUrl(mergeRequest.commitSha ?? '', this.#projectPath)})`,
);
}

mergeRequestSections[section.title].push(title);
}
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ abstract class GitService {
}

abstract getMergeRequests(milestone: string, projectPath: string): Promise<Array<MergeRequest>>;

abstract getCommitUrl(commitSha: string, projectPath: string): string;
}

export = GitService;
15 changes: 14 additions & 1 deletion src/gitlab/gitlabService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import Url = require('url');
import Path = require('path');

import GitService = require('../gitService');
import { gql, GraphQLClient } from 'graphql-request';
import Config = require('../interfaces/config');
import MergeRequest = require('../interfaces/milestone');

import { gql, GraphQLClient } from 'graphql-request';

class GitLabService extends GitService {
#client: GraphQLClient;

Expand Down Expand Up @@ -33,6 +37,7 @@ class GitLabService extends GitService {
title
}
}
mergeCommitSha
}
}
}
Expand All @@ -49,9 +54,17 @@ class GitLabService extends GitService {
title: mergeRequest.title,
labels,
participants,
commitSha: mergeRequest.mergeCommitSha,
};
});
}

getCommitUrl(commitSha: string, projectPath: string): string {
const commitUrl = new Url.URL(this.config.serviceUrl);
commitUrl.pathname = Path.join(projectPath, '-', 'commit', commitSha);

return commitUrl.toString();
}
}

export = GitLabService;
1 change: 1 addition & 0 deletions src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Config {
externalIssuesUrl?: string;
externalIssuesProjects?: Array<string>;
enableExternalIssuesTracker?: boolean;
enableCommitSha?: boolean;
}

export = Config;
1 change: 1 addition & 0 deletions src/interfaces/milestone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ interface MergeRequest {
title: string;
labels: Array<string>;
participants: Array<string>;
commitSha?: string;
}

export = MergeRequest;

0 comments on commit 730afec

Please sign in to comment.