Skip to content

Commit

Permalink
Fixed exception from getVcsRoot on build with personal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Gref-Viau authored and netwolfuk committed Apr 23, 2019
1 parent e15f436 commit 470b215
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@

import jetbrains.buildServer.vcs.SVcsModification;
import jetbrains.buildServer.vcs.VcsFileModification;
import jetbrains.buildServer.vcs.VcsRootInstance;
import org.jetbrains.annotations.Nullable;


public class WebHooksChange {

private static @Nullable String tryGetVcsRootName(final SVcsModification modification) {
if(modification.isPersonal()) {
return null;
}

final VcsRootInstance vcsRoot;
try {
vcsRoot = modification.getVcsRoot();
} catch(UnsupportedOperationException e) {
// Modifications tied to personal changes don't have a backing VCS root, and throw when trying
// to access getVcsRoot() (see issue #132)
return null;
}

return vcsRoot.getName();
}

public static WebHooksChange build(SVcsModification modification) {
WebHooksChange change = new WebHooksChange();
change.setComment(modification.getDescription());
change.setUsername(modification.getUserName());
change.setVcsRoot(modification.getVcsRoot().getName());
change.setVcsRoot(tryGetVcsRootName(modification));
for (VcsFileModification fileModification: modification.getChanges()){
change.files.add(fileModification.getRelativeFileName());
}
Expand All @@ -29,7 +48,7 @@ public static WebHooksChange build(SVcsModification modification) {
private void setVcsRoot(String name) {
this.vcsRoot = name;
}

public String getVcsRoot() {
return vcsRoot;
}
Expand Down

0 comments on commit 470b215

Please sign in to comment.