33 import java.util.Optional;
34 import java.util.stream.Collectors;
35
36 class PullRequestInstance {
37 private final PullRequest pr;
38 private final Repository localRepo;
39 private final Hash targetHash;
40 private final Hash headHash;
41 private final Hash baseHash;
42 private final URI issueTracker;
43 private final String projectPrefix;
44
45 PullRequestInstance(Path localRepoPath, PullRequest pr, URI issueTracker, String projectPrefix) {
46 this.pr = pr;
47 this.issueTracker = issueTracker;
48 this.projectPrefix = projectPrefix;
49
50 // Materialize the PR's target ref
51 try {
52 var repository = pr.repository();
53 localRepo = Repository.materialize(localRepoPath, repository.url(), pr.targetRef());
54 targetHash = localRepo.fetch(repository.url(), pr.targetRef());
55 headHash = localRepo.fetch(repository.url(), pr.headHash().hex());
56 baseHash = localRepo.mergeBase(targetHash, headHash);
57 } catch (IOException e) {
58 throw new UncheckedIOException(e);
59 }
60 }
61
62 Repository localRepo() {
63 return this.localRepo;
64 }
65
66 Hash baseHash() {
67 return this.baseHash;
68 }
69
70 Hash headHash() {
71 return this.headHash;
72 }
73
|
33 import java.util.Optional;
34 import java.util.stream.Collectors;
35
36 class PullRequestInstance {
37 private final PullRequest pr;
38 private final Repository localRepo;
39 private final Hash targetHash;
40 private final Hash headHash;
41 private final Hash baseHash;
42 private final URI issueTracker;
43 private final String projectPrefix;
44
45 PullRequestInstance(Path localRepoPath, PullRequest pr, URI issueTracker, String projectPrefix) {
46 this.pr = pr;
47 this.issueTracker = issueTracker;
48 this.projectPrefix = projectPrefix;
49
50 // Materialize the PR's target ref
51 try {
52 var repository = pr.repository();
53 localRepo = Repository.materialize(localRepoPath, repository.url(),
54 "+" + pr.targetRef() + ":mlbridge_prinstance_" + repository.name());
55 targetHash = localRepo.fetch(repository.url(), pr.targetRef());
56 headHash = localRepo.fetch(repository.url(), pr.headHash().hex());
57 baseHash = localRepo.mergeBase(targetHash, headHash);
58 } catch (IOException e) {
59 throw new UncheckedIOException(e);
60 }
61 }
62
63 Repository localRepo() {
64 return this.localRepo;
65 }
66
67 Hash baseHash() {
68 return this.baseHash;
69 }
70
71 Hash headHash() {
72 return this.headHash;
73 }
74
|