KocproZ / jenkins-discord

A post-build plugin that sends the build status to a Discord channel.
MIT License
39 stars 36 forks source link

Crashes when used with some SCMs #5

Closed Dahlgren closed 7 years ago

Dahlgren commented 7 years ago

https://github.com/jammehcow/jenkins-discord/blob/31cf85ffed2f2843322dab9a25321ffb161bddd3/src/main/java/nz/co/jammehcow/jenkinsdiscord/util/EmbedDescription.java#L36

The entry.getCommitId().substring(0, 6) required the commit id to have at least 6 characters. This is not always the case such as when using SVN as SCM in Jenkins. SVN commit id is an incremented integer value but of course is represented as a string when getCommitId() is called. If the repository contains too "few" commits, less than 100 000, the hook will crash when formatting the description.

jupjohn commented 7 years ago

I've fixed that commit id issue but I'm unsure what you mean regarding the commits. Are you talking about the total amount of commits in the repository affecting the output? That's awfully weird.

Dahlgren commented 7 years ago

entry.getCommitId() string contains less than 6 characters before reaching 100 000 commits using SVN. It's an incremented integer value, not a hash like with Git or Mercurial. I.e. "12345" when there are 12345 commits. Since entry.getCommitId().substring(0, 6) tries to fetch the first 6 characters an exception is thrown if SVN is used as the SCM and there is less than 100 000 commits (commitId "100000").

Dahlgren commented 7 years ago

Since shortened commit id doesn't make sense for SVN the simplest solution would be to check if build SCM is SVN and if so print the entire commit id.

jupjohn commented 7 years ago

It's now checking just for numbers and won't shorten is that's the case. I'm not closing this until you give me the thumbs up.

jupjohn commented 7 years ago

It now checks for the SCM type. Didn't realise that was a thing, cheers.