Skip to content

Commit 8f5ea85

Browse files
jgangemiKostyaSha
authored andcommitted
- fixed button used to trigger branch rebuild (#188)
1 parent ce3e263 commit 8f5ea85

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

  • github-pullrequest-plugin/src/main

github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/GitHubBranchRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public String getUrlName() {
106106
return map;
107107
}
108108

109+
@Override
109110
@RequirePOST
110111
public FormValidation doClearRepo() throws IOException {
111112
FormValidation result;
@@ -127,6 +128,7 @@ public FormValidation doClearRepo() throws IOException {
127128
}
128129

129130
@Override
131+
@RequirePOST
130132
public FormValidation doRunTrigger() throws IOException {
131133
FormValidation result;
132134
try {
@@ -153,6 +155,7 @@ public FormValidation doRunTrigger() throws IOException {
153155
}
154156

155157
@Override
158+
@RequirePOST
156159
public FormValidation doRebuildFailed() throws IOException {
157160
FormValidation result;
158161
try {
@@ -177,6 +180,7 @@ public FormValidation doRebuildFailed() throws IOException {
177180
}
178181

179182
@Override
183+
@RequirePOST
180184
public FormValidation doRebuild(StaplerRequest req) throws IOException {
181185
FormValidation result;
182186

github-pullrequest-plugin/src/main/resources/com/github/kostyasha/github/integration/branch/GitHubBranchRepository/index.groovy

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.kostyasha.github.integration.branch.GitHubBranchRepository
22

33
import com.github.kostyasha.github.integration.branch.GitHubBranchCause
44
import hudson.model.Item
5+
import org.apache.commons.lang3.StringEscapeUtils
56

67
def f = namespace(lib.FormTagLib);
78
def l = namespace(lib.LayoutTagLib);
@@ -18,6 +19,15 @@ def makeBuildItem(def runs) {
1819
}
1920
}
2021

22+
def escapeBranchName(def branchName) {
23+
// escape anything that isn't alphanumeric
24+
return StringEscapeUtils.escapeEcmaScript(branchName);
25+
}
26+
27+
def makeRebuildId(def branchName) {
28+
// replace anything that isn't alphanumeric so it's valid html
29+
return ("rebuildResult" + branchName).replaceAll(/([^a-zA-Z0-9])/, '');
30+
}
2131

2232
l.layout(title: "GitHub Branch Status") {
2333
st.include(page: "sidepanel", it: my.job)
@@ -55,9 +65,10 @@ l.layout(title: "GitHub Branch Status") {
5565
if (h.hasPermission(Item.BUILD)) {
5666
tr() {
5767
td() {
58-
def rebuildId = "rebuildResult" + branch.name;
68+
def rebuildId = makeRebuildId(branch.name);
69+
def escaped = escapeBranchName(branch.name);
5970
form(method: "post", action: "rebuild",
60-
onsubmit: "return callFeature(this, ${rebuildId}, {'branch' : ${branch.name} })") {
71+
onsubmit: "return callFeature(this, ${rebuildId}, {'branchName' : '${escaped}' })") {
6172
f.submit(value: _("Rebuild"))
6273
div(id: rebuildId)
6374
}

0 commit comments

Comments
 (0)