-
Notifications
You must be signed in to change notification settings - Fork 401
/
Copy pathGitHubTrigger.java
87 lines (78 loc) · 3.51 KB
/
GitHubTrigger.java
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
package com.cloudbees.jenkins;
import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractProject;
import hudson.model.Item;
import hudson.triggers.Trigger;
import jenkins.model.ParameterizedJobMixIn;
import java.util.Collection;
import java.util.Set;
/**
* Optional interface that can be implemented by {@link Trigger} that watches out for a change in GitHub
* and triggers a build.
*
* @author aaronwalker
* @deprecated not used any more
*/
public interface GitHubTrigger {
@Deprecated
void onPost();
// TODO: document me
void onPost(String triggeredByUser, String triggeredByRef);
/**
* Obtains the list of the repositories that this trigger is looking at.
*
* If the implementation of this class maintain its own list of GitHub repositories, it should
* continue to implement this method for backward compatibility, and it gets picked up by
* {@link GitHubRepositoryNameContributor#parseAssociatedNames(AbstractProject)}.
*
* <p>
* Alternatively, if the implementation doesn't worry about the backward compatibility, it can
* implement this method to return an empty collection, then just implement {@link GitHubRepositoryNameContributor}.
*
* @deprecated Call {@link GitHubRepositoryNameContributor#parseAssociatedNames(AbstractProject)} instead.
*/
Set<GitHubRepositoryName> getGitHubRepositories();
/**
* Obtains the list of the branches that this trigger is looking at.
*
* If the implementation of this class maintain its own list of GitHub branches, it should
* continue to implement this method for backward compatibility, and it gets picked up by
* {@link GitHubRepositoryNameContributor#parseAssociatedBranches(AbstractProject)}.
*
* <p>
* Alternatively, if the implementation doesn't worry about the backward compatibility, it can
* implement this method to return an empty collection, then just implement {@link GitHubRepositoryNameContributor}.
*
* @deprecated
* Call {@link GitHubRepositoryNameContributor#parseAssociatedBranches(AbstractProject)} instead.
*/
Set<GitHubBranch> getGitHubBranches();
/**
* Contributes {@link GitHubRepositoryName} from {@link GitHubTrigger#getGitHubRepositories()}
* and {@link GitHubBranch} from {@link GitHubTrigger#getGitHubBranches()} for
* backward compatibility.
*/
@Extension
class GitHubRepositoryNameContributorImpl extends GitHubRepositoryNameContributor {
@Override
public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) {
if (item instanceof ParameterizedJobMixIn.ParameterizedJob) {
ParameterizedJobMixIn.ParameterizedJob p = (ParameterizedJobMixIn.ParameterizedJob) item;
// TODO use standard method in 1.621+
for (GitHubTrigger ght : Util.filter(p.getTriggers().values(), GitHubTrigger.class)) {
result.addAll(ght.getGitHubRepositories());
}
}
}
@Override
public void parseAssociatedBranches(Item item, Collection<GitHubBranch> result) {
if (item instanceof ParameterizedJobMixIn.ParameterizedJob) {
ParameterizedJobMixIn.ParameterizedJob p = (ParameterizedJobMixIn.ParameterizedJob) item;
for (GitHubTrigger ght : Util.filter(p.getTriggers().values(), GitHubTrigger.class)) {
result.addAll(ght.getGitHubBranches());
}
}
}
}
}