-
Notifications
You must be signed in to change notification settings - Fork 776
Expand file tree
/
Copy pathGHArtifact.java
More file actions
142 lines (123 loc) · 3.48 KB
/
GHArtifact.java
File metadata and controls
142 lines (123 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonIgnore;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.function.InputStreamFunction;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import java.util.Objects;
import static java.util.Objects.requireNonNull;
// TODO: Auto-generated Javadoc
/**
* An artifact from a workflow run.
*
* @author Guillaume Smet
*/
public class GHArtifact extends GHObject {
private String archiveDownloadUrl;
private boolean expired;
private String expiresAt;
private String name;
// Not provided by the API.
@JsonIgnore
private GHRepository owner;
private long sizeInBytes;
/**
* Create default GHArtifact instance
*/
public GHArtifact() {
}
/**
* Deletes the artifact.
*
* @throws IOException
* the io exception
*/
public void delete() throws IOException {
root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send();
}
/**
* Downloads the artifact.
*
* @param <T>
* the type of result
* @param streamFunction
* The {@link InputStreamFunction} that will process the stream
* @return the result of reading the stream.
* @throws IOException
* The IO exception.
*/
public <T> T download(InputStreamFunction<T> streamFunction) throws IOException {
requireNonNull(streamFunction, "Stream function must not be null");
return root().createRequest().method("GET").withUrlPath(getApiRoute(), "zip").fetchStream(streamFunction);
}
/**
* Gets the archive download URL.
*
* @return the archive download URL
*/
public URL getArchiveDownloadUrl() {
return GitHubClient.parseURL(archiveDownloadUrl);
}
/**
* Gets the date at which this artifact will expire.
*
* @return the date of expiration
*/
public Date getExpiresAt() {
return GitHubClient.parseDate(expiresAt);
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Repository to which the artifact belongs.
*
* @return the repository
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHRepository getRepository() {
return owner;
}
/**
* Gets the size of the artifact in bytes.
*
* @return the size
*/
public long getSizeInBytes() {
return sizeInBytes;
}
/**
* If this artifact has expired.
*
* @return if the artifact has expired
*/
public boolean isExpired() {
return expired;
}
private String getApiRoute() {
if (owner == null) {
// Workflow runs returned from search to do not have an owner. Attempt to use url.
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/");
}
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/actions/artifacts/" + getId();
}
/**
* Wrap up.
*
* @param owner
* the owner
* @return the GH artifact
*/
GHArtifact wrapUp(GHRepository owner) {
this.owner = owner;
return this;
}
}