| skipped 9 lines |
10 | 10 | | |
11 | 11 | | import javax.annotation.Nullable; |
12 | 12 | | |
| 13 | + | import org.apache.wicket.Component; |
13 | 14 | | import org.apache.wicket.ajax.AjaxRequestTarget; |
14 | 15 | | import org.apache.wicket.ajax.markup.html.AjaxLink; |
| 16 | + | import org.apache.wicket.markup.html.basic.Label; |
15 | 17 | | import org.eclipse.jgit.lib.ObjectId; |
16 | 18 | | |
17 | 19 | | import com.google.common.base.Preconditions; |
| skipped 15 lines |
33 | 35 | | import io.onedev.server.security.SecurityUtils; |
34 | 36 | | import io.onedev.server.util.script.identity.JobIdentity; |
35 | 37 | | import io.onedev.server.util.script.identity.ScriptIdentity; |
| 38 | + | import io.onedev.server.web.component.modal.message.MessageModal; |
36 | 39 | | import io.onedev.server.web.page.project.builds.detail.dashboard.BuildDashboardPage; |
37 | 40 | | import io.onedev.server.web.page.project.builds.detail.log.BuildLogPage; |
38 | 41 | | |
| skipped 35 lines |
74 | 77 | | |
75 | 78 | | if (refName != null) { |
76 | 79 | | refNames = Lists.newArrayList(refName); |
| 80 | + | } else if (getPullRequest() != null) { |
| 81 | + | refNames = Lists.newArrayList(getPullRequest().getMergeRef()); |
77 | 82 | | } else { |
78 | 83 | | refNames = refs.stream() |
79 | 84 | | .filter(it->descendants.contains(it.getPeeledObj())) |
| skipped 1 lines |
81 | 86 | | .collect(Collectors.toList()); |
82 | 87 | | } |
83 | 88 | | |
84 | | - | Job job = Preconditions.checkNotNull(buildSpec.getJobMap().get(jobName)); |
85 | | - | if (refNames.size() > 1 || !job.getParamSpecs().isEmpty()) { |
86 | | - | Serializable paramBean; |
87 | | - | try { |
88 | | - | paramBean = ParamSupply.defineBeanClass(job.getParamSpecs()).newInstance(); |
89 | | - | } catch (InstantiationException | IllegalAccessException e) { |
90 | | - | throw new RuntimeException(e); |
91 | | - | } |
| 89 | + | if (!refNames.isEmpty()) { |
| 90 | + | Job job = Preconditions.checkNotNull(buildSpec.getJobMap().get(jobName)); |
| 91 | + | if (refNames.size() > 1 || !job.getParamSpecs().isEmpty()) { |
| 92 | + | Serializable paramBean; |
| 93 | + | try { |
| 94 | + | paramBean = ParamSupply.defineBeanClass(job.getParamSpecs()).newInstance(); |
| 95 | + | } catch (InstantiationException | IllegalAccessException e) { |
| 96 | + | throw new RuntimeException(e); |
| 97 | + | } |
92 | 98 | | |
93 | | - | new BuildOptionModalPanel(target, refNames, paramBean) { |
| 99 | + | new BuildOptionModalPanel(target, refNames, paramBean) { |
94 | 100 | | |
95 | | - | @Override |
96 | | - | protected void onSave(AjaxRequestTarget target, Collection<String> selectedRefNames, |
97 | | - | Serializable populatedParamBean) { |
98 | | - | Map<String, List<String>> paramMap = ParamSupply.getParamMap( |
99 | | - | job, populatedParamBean, job.getParamSpecMap().keySet()); |
100 | | - | List<Build> builds = new ArrayList<>(); |
101 | | - | if (selectedRefNames.isEmpty()) |
102 | | - | selectedRefNames.add(null); |
103 | | - | for (String refName: selectedRefNames) { |
104 | | - | SubmitReason reason = new SubmitReason() { |
| 101 | + | @Override |
| 102 | + | protected void onSave(AjaxRequestTarget target, Collection<String> selectedRefNames, |
| 103 | + | Serializable populatedParamBean) { |
| 104 | + | Map<String, List<String>> paramMap = ParamSupply.getParamMap( |
| 105 | + | job, populatedParamBean, job.getParamSpecMap().keySet()); |
| 106 | + | List<Build> builds = new ArrayList<>(); |
| 107 | + | for (String refName: selectedRefNames) { |
| 108 | + | SubmitReason reason = new SubmitReason() { |
105 | 109 | | |
106 | | - | @Override |
107 | | - | public String getRefName() { |
108 | | - | return refName; |
109 | | - | } |
| 110 | + | @Override |
| 111 | + | public String getRefName() { |
| 112 | + | return refName; |
| 113 | + | } |
110 | 114 | | |
111 | | - | @Override |
112 | | - | public PullRequest getPullRequest() { |
113 | | - | return RunJobLink.this.getPullRequest(); |
114 | | - | } |
| 115 | + | @Override |
| 116 | + | public PullRequest getPullRequest() { |
| 117 | + | return RunJobLink.this.getPullRequest(); |
| 118 | + | } |
115 | 119 | | |
116 | | - | @Override |
117 | | - | public String getDescription() { |
118 | | - | return "Submitted manually"; |
119 | | - | } |
| 120 | + | @Override |
| 121 | + | public String getDescription() { |
| 122 | + | return "Submitted manually"; |
| 123 | + | } |
120 | 124 | | |
121 | | - | }; |
122 | | - | builds.add(getJobManager().submit(getProject(), commitId, job.getName(), |
123 | | - | paramMap, reason)); |
| 125 | + | }; |
| 126 | + | builds.add(getJobManager().submit(getProject(), commitId, job.getName(), |
| 127 | + | paramMap, reason)); |
| 128 | + | } |
| 129 | + | if (builds.size() == 1) |
| 130 | + | setResponsePage(BuildDashboardPage.class, BuildDashboardPage.paramsOf(builds.iterator().next())); |
| 131 | + | else |
| 132 | + | close(); |
124 | 133 | | } |
125 | | - | if (builds.size() == 1) |
126 | | - | setResponsePage(BuildDashboardPage.class, BuildDashboardPage.paramsOf(builds.iterator().next())); |
127 | | - | else |
128 | | - | close(); |
129 | | - | } |
130 | 134 | | |
131 | | - | @Override |
132 | | - | public List<String> getInputNames() { |
133 | | - | return new ArrayList<>(job.getParamSpecMap().keySet()); |
134 | | - | } |
| 135 | + | @Override |
| 136 | + | public List<String> getInputNames() { |
| 137 | + | return new ArrayList<>(job.getParamSpecMap().keySet()); |
| 138 | + | } |
135 | 139 | | |
136 | | - | @Override |
137 | | - | public ParamSpec getInputSpec(String paramName) { |
138 | | - | return Preconditions.checkNotNull(job.getParamSpecMap().get(paramName)); |
139 | | - | } |
| 140 | + | @Override |
| 141 | + | public ParamSpec getInputSpec(String paramName) { |
| 142 | + | return Preconditions.checkNotNull(job.getParamSpecMap().get(paramName)); |
| 143 | + | } |
140 | 144 | | |
141 | | - | @Override |
142 | | - | public ScriptIdentity getScriptIdentity() { |
143 | | - | return new JobIdentity(getProject(), commitId); |
144 | | - | } |
| 145 | + | @Override |
| 146 | + | public ScriptIdentity getScriptIdentity() { |
| 147 | + | return new JobIdentity(getProject(), commitId); |
| 148 | + | } |
145 | 149 | | |
146 | | - | }; |
147 | | - | } else { |
148 | | - | SubmitReason reason = new SubmitReason() { |
| 150 | + | }; |
| 151 | + | } else { |
| 152 | + | SubmitReason reason = new SubmitReason() { |
149 | 153 | | |
150 | | - | @Override |
151 | | - | public String getRefName() { |
152 | | - | if (refNames.isEmpty()) |
153 | | - | return null; |
154 | | - | else |
| 154 | + | @Override |
| 155 | + | public String getRefName() { |
155 | 156 | | return refNames.iterator().next(); |
156 | | - | } |
| 157 | + | } |
| 158 | + | |
| 159 | + | @Override |
| 160 | + | public PullRequest getPullRequest() { |
| 161 | + | return RunJobLink.this.getPullRequest(); |
| 162 | + | } |
| 163 | + | |
| 164 | + | @Override |
| 165 | + | public String getDescription() { |
| 166 | + | return "Submitted manually"; |
| 167 | + | } |
157 | 168 | | |
158 | | - | @Override |
159 | | - | public PullRequest getPullRequest() { |
160 | | - | return RunJobLink.this.getPullRequest(); |
161 | | - | } |
| 169 | + | }; |
| 170 | + | Build build = getJobManager().submit(getProject(), commitId, job.getName(), |
| 171 | + | new HashMap<>(), reason); |
| 172 | + | setResponsePage(BuildLogPage.class, BuildLogPage.paramsOf(build)); |
| 173 | + | } |
| 174 | + | } else { |
| 175 | + | new MessageModal(target) { |
162 | 176 | | |
163 | 177 | | @Override |
164 | | - | public String getDescription() { |
165 | | - | return "Submitted manually"; |
| 178 | + | protected Component newMessageContent(String componentId) { |
| 179 | + | return new Label(componentId, "No refs to build on behalf of"); |
166 | 180 | | } |
167 | 181 | | |
168 | 182 | | }; |
169 | | - | Build build = getJobManager().submit(getProject(), commitId, job.getName(), |
170 | | - | new HashMap<>(), reason); |
171 | | - | setResponsePage(BuildLogPage.class, BuildLogPage.paramsOf(build)); |
172 | 183 | | } |
173 | 184 | | } |
174 | 185 | | |
| skipped 12 lines |