-
Notifications
You must be signed in to change notification settings - Fork 776
Expand file tree
/
Copy pathGHContentDeleter.java
More file actions
177 lines (161 loc) · 5.35 KB
/
GHContentDeleter.java
File metadata and controls
177 lines (161 loc) · 5.35 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.io.IOException;
import java.time.Instant;
import java.util.Date;
/**
* Builder for deleting repository content with support for specifying author and committer information.
*
* <p>
* Obtain an instance via {@link GHContent#createDelete()}.
*
* @see GHContent#createDelete()
*/
public final class GHContentDeleter {
@JsonInclude(Include.NON_NULL)
private static final class UserInfo {
private final String date;
private final String email;
private final String name;
private UserInfo(String name, String email, Instant date) {
this.name = name;
this.email = email;
this.date = date != null ? GitHubClient.printInstant(date) : null;
}
}
private final GHContent content;
private final Requester req;
GHContentDeleter(GHContent content) {
this.content = content;
final GHRepository repository = content.getOwner();
this.req = repository.root()
.createRequest()
.method("DELETE")
.inBody()
.with("path", content.getPath())
.with("sha", content.getSha());
}
/**
* Configures the author of the commit. If not specified, the authenticated user is used as the author.
*
* @param name
* the name of the author
* @param email
* the email of the author
* @return this deleter
*/
public GHContentDeleter author(String name, String email) {
return author(name, email, (Instant) null);
}
/**
* Configures the author of the commit. If not specified, the authenticated user is used as the author.
*
* @param name
* the name of the author
* @param email
* the email of the author
* @param date
* the date of the authoring
* @return this deleter
* @deprecated use {@link #author(String, String, Instant)} instead
*/
@Deprecated
public GHContentDeleter author(String name, String email, Date date) {
return author(name, email, GitHubClient.toInstantOrNull(date));
}
/**
* Configures the author of the commit. If not specified, the authenticated user is used as the author.
*
* @param name
* the name of the author
* @param email
* the email of the author
* @param date
* the timestamp for the authoring
* @return this deleter
*/
public GHContentDeleter author(String name, String email, Instant date) {
req.with("author", new UserInfo(name, email, date));
return this;
}
/**
* Sets the branch to delete the content from.
*
* @param branch
* the branch name
* @return this deleter
*/
public GHContentDeleter branch(String branch) {
req.with("branch", branch);
return this;
}
/**
* Commits the deletion.
*
* @return the response containing the commit information
* @throws IOException
* the io exception
*/
public GHContentUpdateResponse commit() throws IOException {
final GHRepository repository = content.getOwner();
GHContentUpdateResponse response = req.withUrlPath(GHContent.getApiRoute(repository, content.getPath()))
.fetch(GHContentUpdateResponse.class);
response.getCommit().wrapUp(repository);
return response;
}
/**
* Configures the committer of the commit. If not specified, the authenticated user is used as the committer.
*
* @param name
* the name of the committer
* @param email
* the email of the committer
* @return this deleter
*/
public GHContentDeleter committer(String name, String email) {
return committer(name, email, (Instant) null);
}
/**
* Configures the committer of the commit. If not specified, the authenticated user is used as the committer.
*
* @param name
* the name of the committer
* @param email
* the email of the committer
* @param date
* the date of the commit
* @return this deleter
* @deprecated use {@link #committer(String, String, Instant)} instead
*/
@Deprecated
public GHContentDeleter committer(String name, String email, Date date) {
return committer(name, email, GitHubClient.toInstantOrNull(date));
}
/**
* Configures the committer of the commit. If not specified, the authenticated user is used as the committer.
*
* @param name
* the name of the committer
* @param email
* the email of the committer
* @param date
* the timestamp of the commit
* @return this deleter
*/
public GHContentDeleter committer(String name, String email, Instant date) {
req.with("committer", new UserInfo(name, email, date));
return this;
}
/**
* Sets the commit message.
*
* @param message
* the commit message
* @return this deleter
*/
public GHContentDeleter message(String message) {
req.with("message", message);
return this;
}
}