< prev index next >

test/src/main/java/org/openjdk/skara/test/TestPullRequest.java

Print this page

 22  */
 23 package org.openjdk.skara.test;
 24 
 25 import org.openjdk.skara.host.*;
 26 import org.openjdk.skara.vcs.Hash;
 27 
 28 import java.io.*;
 29 import java.net.*;
 30 import java.time.ZonedDateTime;
 31 import java.util.*;
 32 import java.util.function.Function;
 33 import java.util.stream.Collectors;
 34 
 35 public class TestPullRequest implements PullRequest {
 36     private final TestHostedRepository repository;
 37     private final String id;
 38     private final HostUserDetails author;
 39     private final HostUserDetails user;
 40     private final String targetRef;
 41     private final String sourceRef;
 42     private final String title;
 43     private final List<String> body;
 44     private final PullRequestData data;
 45 
 46     private static class PullRequestData {
 47         private Hash headHash;
 48         PullRequest.State state = PullRequest.State.OPEN;
 49         String body = "";

 50         final List<Comment> comments = new ArrayList<>();
 51         final List<ReviewComment> reviewComments = new ArrayList<>();
 52         final Set<Check> checks = new HashSet<>();
 53         final Set<String> labels = new HashSet<>();
 54         final List<Review> reviews = new ArrayList<>();
 55         ZonedDateTime created = ZonedDateTime.now();
 56         ZonedDateTime lastUpdate = created;
 57     }
 58 
 59     private TestPullRequest(TestHostedRepository repository, String id, HostUserDetails author, HostUserDetails user, String targetRef, String sourceRef, String title, List<String> body, PullRequestData data) {
 60         this.repository = repository;
 61         this.id = id;
 62         this.author = author;
 63         this.user = user;
 64         this.targetRef = targetRef;
 65         this.sourceRef = sourceRef;
 66         this.title = title;
 67         this.body = body;
 68         this.data = data;
 69 
 70         try {
 71             var headHash = repository.localRepository().resolve(sourceRef).orElseThrow();
 72             if (!headHash.equals(data.headHash)) {
 73                 data.headHash = headHash;
 74                 data.lastUpdate = ZonedDateTime.now();
 75             }
 76         } catch (IOException e) {
 77             throw new UncheckedIOException(e);
 78         }
 79     }
 80 
 81     static TestPullRequest createNew(TestHostedRepository repository, String id, String targetRef, String sourceRef, String title, List<String> body) {
 82         var data = new PullRequestData();

 83         data.body = String.join("\n", body);
 84         var pr = new TestPullRequest(repository, id, repository.host().getCurrentUserDetails(), repository.host().getCurrentUserDetails(), targetRef, sourceRef, title, body, data);
 85         return pr;
 86     }
 87 
 88     static TestPullRequest createFrom(TestHostedRepository repository, TestPullRequest other) {
 89         var pr = new TestPullRequest(repository, other.id, other.author, repository.host().getCurrentUserDetails(), other.targetRef, other.sourceRef, other.title, other.body, other.data);
 90         return pr;
 91     }
 92 
 93     @Override
 94     public HostedRepository repository() {
 95         return repository;
 96     }
 97 
 98     @Override
 99     public String getId() {
100         return id;
101     }
102 
103     @Override
104     public HostUserDetails getAuthor() {
105         return author;
106     }
107 
108     @Override
109     public List<Review> getReviews() {

155         return data.headHash;
156     }
157 
158     @Override
159     public String getSourceRef() {
160         return sourceRef;
161     }
162 
163     @Override
164     public String getTargetRef() {
165         return targetRef;
166     }
167 
168     @Override
169     public Hash getTargetHash() {
170         return repository.getBranchHash(targetRef);
171     }
172 
173     @Override
174     public String getTitle() {
175         return title;






176     }
177 
178     @Override
179     public String getBody() {
180         return data.body;
181     }
182 
183     @Override
184     public void setBody(String body) {
185         data.body = body;
186         data.lastUpdate = ZonedDateTime.now();
187     }
188 
189     @Override
190     public List<Comment> getComments() {
191         return new ArrayList<>(data.comments);
192     }
193 
194     @Override
195     public Comment addComment(String body) {

 22  */
 23 package org.openjdk.skara.test;
 24 
 25 import org.openjdk.skara.host.*;
 26 import org.openjdk.skara.vcs.Hash;
 27 
 28 import java.io.*;
 29 import java.net.*;
 30 import java.time.ZonedDateTime;
 31 import java.util.*;
 32 import java.util.function.Function;
 33 import java.util.stream.Collectors;
 34 
 35 public class TestPullRequest implements PullRequest {
 36     private final TestHostedRepository repository;
 37     private final String id;
 38     private final HostUserDetails author;
 39     private final HostUserDetails user;
 40     private final String targetRef;
 41     private final String sourceRef;


 42     private final PullRequestData data;
 43 
 44     private static class PullRequestData {
 45         private Hash headHash;
 46         PullRequest.State state = PullRequest.State.OPEN;
 47         String body = "";
 48         String title = "";
 49         final List<Comment> comments = new ArrayList<>();
 50         final List<ReviewComment> reviewComments = new ArrayList<>();
 51         final Set<Check> checks = new HashSet<>();
 52         final Set<String> labels = new HashSet<>();
 53         final List<Review> reviews = new ArrayList<>();
 54         ZonedDateTime created = ZonedDateTime.now();
 55         ZonedDateTime lastUpdate = created;
 56     }
 57 
 58     private TestPullRequest(TestHostedRepository repository, String id, HostUserDetails author, HostUserDetails user, String targetRef, String sourceRef, PullRequestData data) {
 59         this.repository = repository;
 60         this.id = id;
 61         this.author = author;
 62         this.user = user;
 63         this.targetRef = targetRef;
 64         this.sourceRef = sourceRef;


 65         this.data = data;
 66 
 67         try {
 68             var headHash = repository.localRepository().resolve(sourceRef).orElseThrow();
 69             if (!headHash.equals(data.headHash)) {
 70                 data.headHash = headHash;
 71                 data.lastUpdate = ZonedDateTime.now();
 72             }
 73         } catch (IOException e) {
 74             throw new UncheckedIOException(e);
 75         }
 76     }
 77 
 78     static TestPullRequest createNew(TestHostedRepository repository, String id, String targetRef, String sourceRef, String title, List<String> body) {
 79         var data = new PullRequestData();
 80         data.title = title;
 81         data.body = String.join("\n", body);
 82         var pr = new TestPullRequest(repository, id, repository.host().getCurrentUserDetails(), repository.host().getCurrentUserDetails(), targetRef, sourceRef, data);
 83         return pr;
 84     }
 85 
 86     static TestPullRequest createFrom(TestHostedRepository repository, TestPullRequest other) {
 87         var pr = new TestPullRequest(repository, other.id, other.author, repository.host().getCurrentUserDetails(), other.targetRef, other.sourceRef, other.data);
 88         return pr;
 89     }
 90 
 91     @Override
 92     public HostedRepository repository() {
 93         return repository;
 94     }
 95 
 96     @Override
 97     public String getId() {
 98         return id;
 99     }
100 
101     @Override
102     public HostUserDetails getAuthor() {
103         return author;
104     }
105 
106     @Override
107     public List<Review> getReviews() {

153         return data.headHash;
154     }
155 
156     @Override
157     public String getSourceRef() {
158         return sourceRef;
159     }
160 
161     @Override
162     public String getTargetRef() {
163         return targetRef;
164     }
165 
166     @Override
167     public Hash getTargetHash() {
168         return repository.getBranchHash(targetRef);
169     }
170 
171     @Override
172     public String getTitle() {
173         return data.title;
174     }
175 
176     @Override
177     public void setTitle(String title) {
178         data.title = title;
179         data.lastUpdate = ZonedDateTime.now();
180     }
181 
182     @Override
183     public String getBody() {
184         return data.body;
185     }
186 
187     @Override
188     public void setBody(String body) {
189         data.body = body;
190         data.lastUpdate = ZonedDateTime.now();
191     }
192 
193     @Override
194     public List<Comment> getComments() {
195         return new ArrayList<>(data.comments);
196     }
197 
198     @Override
199     public Comment addComment(String body) {
< prev index next >