loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Check disabled workflow when rerun jobs (#26535)

In GitHub, we can not rerun jobs if the workflow is disabled.

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>

authored by

yp05327
silverwind
wxiaoguang
and committed by
GitHub
a4a567f2 b3f71371

+76 -100
+1
options/locale/locale_en-US.ini
··· 3503 3503 workflow.disable_success = Workflow '%s' disabled successfully. 3504 3504 workflow.enable = Enable Workflow 3505 3505 workflow.enable_success = Workflow '%s' enabled successfully. 3506 + workflow.disabled = Workflow is disabled. 3506 3507 3507 3508 need_approval_desc = Need approval to run workflows for fork pull request. 3508 3509
+16 -12
routers/web/repo/actions/view.go
··· 259 259 ctx.JSON(http.StatusOK, resp) 260 260 } 261 261 262 - func RerunOne(ctx *context_module.Context) { 262 + // Rerun will rerun jobs in the given run 263 + // jobIndex = 0 means rerun all jobs 264 + func Rerun(ctx *context_module.Context) { 263 265 runIndex := ctx.ParamsInt64("run") 264 266 jobIndex := ctx.ParamsInt64("job") 265 267 266 - job, _ := getRunJobs(ctx, runIndex, jobIndex) 267 - if ctx.Written() { 268 + run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex) 269 + if err != nil { 270 + ctx.Error(http.StatusInternalServerError, err.Error()) 268 271 return 269 272 } 270 273 271 - if err := rerunJob(ctx, job); err != nil { 272 - ctx.Error(http.StatusInternalServerError, err.Error()) 274 + // can not rerun job when workflow is disabled 275 + cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions) 276 + cfg := cfgUnit.ActionsConfig() 277 + if cfg.IsWorkflowDisabled(run.WorkflowID) { 278 + ctx.JSONError(ctx.Locale.Tr("actions.workflow.disabled")) 273 279 return 274 280 } 275 281 276 - ctx.JSON(http.StatusOK, struct{}{}) 277 - } 278 - 279 - func RerunAll(ctx *context_module.Context) { 280 - runIndex := ctx.ParamsInt64("run") 281 - 282 - _, jobs := getRunJobs(ctx, runIndex, 0) 282 + job, jobs := getRunJobs(ctx, runIndex, jobIndex) 283 283 if ctx.Written() { 284 284 return 285 + } 286 + 287 + if jobIndex != 0 { 288 + jobs = []*actions_model.ActionRunJob{job} 285 289 } 286 290 287 291 for _, j := range jobs {
+2 -2
routers/web/web.go
··· 1211 1211 m.Combo(""). 1212 1212 Get(actions.View). 1213 1213 Post(web.Bind(actions.ViewRequest{}), actions.ViewPost) 1214 - m.Post("/rerun", reqRepoActionsWriter, actions.RerunOne) 1214 + m.Post("/rerun", reqRepoActionsWriter, actions.Rerun) 1215 1215 m.Get("/logs", actions.Logs) 1216 1216 }) 1217 1217 m.Post("/cancel", reqRepoActionsWriter, actions.Cancel) 1218 1218 m.Post("/approve", reqRepoActionsWriter, actions.Approve) 1219 1219 m.Post("/artifacts", actions.ArtifactsView) 1220 1220 m.Get("/artifacts/{artifact_name}", actions.ArtifactsDownloadView) 1221 - m.Post("/rerun", reqRepoActionsWriter, actions.RerunAll) 1221 + m.Post("/rerun", reqRepoActionsWriter, actions.Rerun) 1222 1222 }) 1223 1223 }, reqRepoActionsReader, actions.MustEnableActions) 1224 1224
+2
templates/base/head_script.tmpl
··· 4 4 If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly. 5 5 */}} 6 6 <script> 7 + {{/* before our JS code gets loaded, use arrays to store errors, then the arrays will be switched to our error handler later */}} 7 8 window.addEventListener('error', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);}); 9 + window.addEventListener('unhandledrejection', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);}); 8 10 window.config = { 9 11 appUrl: '{{AppUrl}}', 10 12 appSubUrl: '{{AppSubUrl}}',
+9 -1
web_src/js/bootstrap.js
··· 20 20 * @param {ErrorEvent} e 21 21 */ 22 22 function processWindowErrorEvent(e) { 23 + if (e.type === 'unhandledrejection') { 24 + showGlobalErrorMessage(`JavaScript promise rejection: ${e.reason}. Open browser console to see more details.`); 25 + return; 26 + } 23 27 if (!e.error && e.lineno === 0 && e.colno === 0 && e.filename === '' && window.navigator.userAgent.includes('FxiOS/')) { 24 28 // At the moment, Firefox (iOS) (10x) has an engine bug. See https://github.com/go-gitea/gitea/issues/20240 25 29 // If a script inserts a newly created (and content changed) element into DOM, there will be a nonsense error event reporting: Script error: line 0, col 0. ··· 30 34 } 31 35 32 36 function initGlobalErrorHandler() { 37 + if (window._globalHandlerErrors?._inited) { 38 + showGlobalErrorMessage(`The global error handler has been initialized, do not initialize it again`); 39 + return; 40 + } 33 41 if (!window.config) { 34 42 showGlobalErrorMessage(`Gitea JavaScript code couldn't run correctly, please check your custom templates`); 35 43 } ··· 40 48 processWindowErrorEvent(e); 41 49 } 42 50 // then, change _globalHandlerErrors to an object with push method, to process further error events directly 43 - window._globalHandlerErrors = {'push': (e) => processWindowErrorEvent(e)}; 51 + window._globalHandlerErrors = {_inited: true, push: (e) => processWindowErrorEvent(e)}; 44 52 } 45 53 46 54 initGlobalErrorHandler();
+2 -13
web_src/js/components/RepoActionView.vue
··· 14 14 <button class="ui basic small compact button red" @click="cancelRun()" v-else-if="run.canCancel"> 15 15 {{ locale.cancel }} 16 16 </button> 17 - <button class="ui basic small compact button gt-mr-0" @click="rerun()" v-else-if="run.canRerun"> 17 + <button class="ui basic small compact button gt-mr-0 link-action" :data-url="`${run.link}/rerun`" v-else-if="run.canRerun"> 18 18 {{ locale.rerun_all }} 19 19 </button> 20 20 </div> ··· 38 38 <span class="job-brief-name gt-mx-3 gt-ellipsis">{{ job.name }}</span> 39 39 </div> 40 40 <span class="job-brief-item-right"> 41 - <SvgIcon name="octicon-sync" role="button" :data-tooltip-content="locale.rerun" class="job-brief-rerun gt-mx-3" @click="rerunJob(index)" v-if="job.canRerun && onHoverRerunIndex === job.id"/> 41 + <SvgIcon name="octicon-sync" role="button" :data-tooltip-content="locale.rerun" class="job-brief-rerun gt-mx-3 link-action" :data-url="`${run.link}/jobs/${index}/rerun`" v-if="job.canRerun && onHoverRerunIndex === job.id"/> 42 42 <span class="step-summary-duration">{{ job.duration }}</span> 43 43 </span> 44 44 </a> ··· 263 263 if (this.currentJobStepsStates[idx].expanded) { 264 264 this.loadJob(); // try to load the data immediately instead of waiting for next timer interval 265 265 } 266 - }, 267 - // rerun a job 268 - async rerunJob(idx) { 269 - const jobLink = `${this.run.link}/jobs/${idx}`; 270 - await this.fetchPost(`${jobLink}/rerun`); 271 - window.location.href = jobLink; 272 - }, 273 - // rerun workflow 274 - async rerun() { 275 - await this.fetchPost(`${this.run.link}/rerun`); 276 - window.location.href = this.run.link; 277 266 }, 278 267 // cancel a run 279 268 cancelRun() {
+44 -72
web_src/js/features/common-global.js
··· 8 8 import {svg} from '../svg.js'; 9 9 import {hideElem, showElem, toggleElem} from '../utils/dom.js'; 10 10 import {htmlEscape} from 'escape-goat'; 11 - import {createTippy, showTemporaryTooltip} from '../modules/tippy.js'; 11 + import {showTemporaryTooltip} from '../modules/tippy.js'; 12 12 import {confirmModal} from './comp/ConfirmModal.js'; 13 13 import {showErrorToast} from '../modules/toast.js'; 14 14 ··· 64 64 }); 65 65 } 66 66 67 - // doRedirect does real redirection to bypass the browser's limitations of "location" 67 + // fetchActionDoRedirect does real redirection to bypass the browser's limitations of "location" 68 68 // more details are in the backend's fetch-redirect handler 69 - function doRedirect(redirect) { 69 + function fetchActionDoRedirect(redirect) { 70 70 const form = document.createElement('form'); 71 71 const input = document.createElement('input'); 72 72 form.method = 'post'; ··· 79 79 form.submit(); 80 80 } 81 81 82 + async function fetchActionDoRequest(actionElem, url, opt) { 83 + try { 84 + const resp = await fetch(url, opt); 85 + if (resp.status === 200) { 86 + let {redirect} = await resp.json(); 87 + redirect = redirect || actionElem.getAttribute('data-redirect'); 88 + actionElem.classList.remove('dirty'); // remove the areYouSure check before reloading 89 + if (redirect) { 90 + fetchActionDoRedirect(redirect); 91 + } else { 92 + window.location.reload(); 93 + } 94 + } else if (resp.status >= 400 && resp.status < 500) { 95 + const data = await resp.json(); 96 + // the code was quite messy, sometimes the backend uses "err", sometimes it uses "error", and even "user_error" 97 + // but at the moment, as a new approach, we only use "errorMessage" here, backend can use JSONError() to respond. 98 + await showErrorToast(data.errorMessage || `server error: ${resp.status}`); 99 + } else { 100 + await showErrorToast(`server error: ${resp.status}`); 101 + } 102 + } catch (e) { 103 + console.error('error when doRequest', e); 104 + actionElem.classList.remove('is-loading', 'small-loading-icon'); 105 + await showErrorToast(i18n.network_error); 106 + } 107 + } 108 + 82 109 async function formFetchAction(e) { 83 110 if (!e.target.classList.contains('form-fetch-action')) return; 84 111 ··· 115 142 reqOpt.body = formData; 116 143 } 117 144 118 - let errorTippy; 119 - const onError = (msg) => { 120 - formEl.classList.remove('is-loading', 'small-loading-icon'); 121 - if (errorTippy) errorTippy.destroy(); 122 - // TODO: use a better toast UI instead of the tippy. If the form height is large, the tippy position is not good 123 - errorTippy = createTippy(formEl, { 124 - content: msg, 125 - interactive: true, 126 - showOnCreate: true, 127 - hideOnClick: true, 128 - role: 'alert', 129 - theme: 'form-fetch-error', 130 - trigger: 'manual', 131 - arrow: false, 132 - }); 133 - }; 134 - 135 - const doRequest = async () => { 136 - try { 137 - const resp = await fetch(reqUrl, reqOpt); 138 - if (resp.status === 200) { 139 - const {redirect} = await resp.json(); 140 - formEl.classList.remove('dirty'); // remove the areYouSure check before reloading 141 - if (redirect) { 142 - doRedirect(redirect); 143 - } else { 144 - window.location.reload(); 145 - } 146 - } else if (resp.status >= 400 && resp.status < 500) { 147 - const data = await resp.json(); 148 - // the code was quite messy, sometimes the backend uses "err", sometimes it uses "error", and even "user_error" 149 - // but at the moment, as a new approach, we only use "errorMessage" here, backend can use JSONError() to respond. 150 - onError(data.errorMessage || `server error: ${resp.status}`); 151 - } else { 152 - onError(`server error: ${resp.status}`); 153 - } 154 - } catch (e) { 155 - console.error('error when doRequest', e); 156 - onError(i18n.network_error); 157 - } 158 - }; 159 - 160 - // TODO: add "confirm" support like "link-action" in the future 161 - await doRequest(); 145 + await fetchActionDoRequest(formEl, reqUrl, reqOpt); 162 146 } 163 147 164 148 export function initGlobalCommon() { ··· 209 193 $('.tabular.menu .item').tab(); 210 194 211 195 document.addEventListener('submit', formFetchAction); 196 + document.addEventListener('click', linkAction); 212 197 } 213 198 214 199 export function initGlobalDropzone() { ··· 269 254 } 270 255 271 256 async function linkAction(e) { 272 - e.preventDefault(); 273 - 274 257 // A "link-action" can post AJAX request to its "data-url" 275 258 // Then the browser is redirected to: the "redirect" in response, or "data-redirect" attribute, or current URL by reloading. 276 259 // If the "link-action" has "data-modal-confirm" attribute, a confirm modal dialog will be shown before taking action. 260 + const el = e.target.closest('.link-action'); 261 + if (!el) return; 277 262 278 - const $this = $(this); 279 - const redirect = $this.attr('data-redirect'); 280 - 281 - const doRequest = () => { 282 - $this.prop('disabled', true); 283 - $.post($this.attr('data-url'), { 284 - _csrf: csrfToken 285 - }).done((data) => { 286 - if (data && data.redirect) { 287 - window.location.href = data.redirect; 288 - } else if (redirect) { 289 - window.location.href = redirect; 290 - } else { 291 - window.location.reload(); 292 - } 293 - }).always(() => { 294 - $this.prop('disabled', false); 295 - }); 263 + e.preventDefault(); 264 + const url = el.getAttribute('data-url'); 265 + const doRequest = async () => { 266 + el.disabled = true; 267 + await fetchActionDoRequest(el, url, {method: 'POST', headers: {'X-Csrf-Token': csrfToken}}); 268 + el.disabled = false; 296 269 }; 297 270 298 - const modalConfirmContent = htmlEscape($this.attr('data-modal-confirm') || ''); 271 + const modalConfirmContent = htmlEscape(el.getAttribute('data-modal-confirm') || ''); 299 272 if (!modalConfirmContent) { 300 - doRequest(); 273 + await doRequest(); 301 274 return; 302 275 } 303 276 304 - const isRisky = $this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative'); 277 + const isRisky = el.classList.contains('red') || el.classList.contains('yellow') || el.classList.contains('orange') || el.classList.contains('negative'); 305 278 if (await confirmModal({content: modalConfirmContent, buttonColor: isRisky ? 'orange' : 'green'})) { 306 - doRequest(); 279 + await doRequest(); 307 280 } 308 281 } 309 282 ··· 354 327 355 328 // Helpers. 356 329 $('.delete-button').on('click', showDeletePopup); 357 - $('.link-action').on('click', linkAction); 358 330 } 359 331 360 332 function initGlobalShowModal() {