Skip to content

Commit cb42daf

Browse files
Git message truncate (#59)
* adding git commit message truncation logic for large messages
1 parent ef3fea9 commit cb42daf

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

api/GrpcHandler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (impl *GrpcHandlerImpl) FetchChanges(ctx context.Context, req *pb.FetchScmC
197197
if res.Commits != nil {
198198
pbGitCommits = make([]*pb.GitCommit, 0, len(res.Commits))
199199
for _, item := range res.Commits {
200-
200+
item.TruncateMessageIfExceedsMaxLength()
201201
mappedCommit, err := impl.mapGitCommit(item)
202202
if err != nil {
203203
impl.logger.Debugw("failed to map git commit from bean to proto specified type",

pkg/git/Bean.go

+7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ type GitCommit struct {
6464
Excluded bool `json:",omitempty"`
6565
}
6666

67+
func (gitCommit *GitCommit) TruncateMessageIfExceedsMaxLength() {
68+
maxLength := 1024
69+
if len(gitCommit.Message) > maxLength {
70+
gitCommit.Message = gitCommit.Message[:maxLength-3] + "..."
71+
}
72+
}
73+
6774
type WebhookAndCiData struct {
6875
ExtraEnvironmentVariables map[string]string `json:"extraEnvironmentVariables"` // extra env variables which will be used for CI
6976
WebhookData *WebhookData `json:"webhookData"`

pkg/git/RepositoryManager.go

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ func (impl RepositoryManagerImpl) ChangesSinceByRepository(repository *git.Repos
269269
Date: commit.Author.When,
270270
Message: commit.Message,
271271
}
272+
gitCommit.TruncateMessageIfExceedsMaxLength()
272273
impl.logger.Debugw("commit dto for repo ", "repo", repository, commit)
273274
gitCommits = append(gitCommits, gitCommit)
274275
itrCounter = itrCounter + 1

0 commit comments

Comments
 (0)