mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-07-07 16:00:04 +02:00

## Summary Inspired by https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-repository and https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#get-a-workflow-run ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Features - [PR](https://codeberg.org/forgejo/forgejo/pulls/7699): <!--number 7699 --><!--line 0 --><!--description bWFrZSBhY3Rpb24gcnVucyBhdmFpbGFibGUgaW4gYXBp-->make action runs available in api<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7699 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: klausfyhn <klausfyhn@gmail.com> Co-committed-by: klausfyhn <klausfyhn@gmail.com>
118 lines
2.9 KiB
Go
118 lines
2.9 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"forgejo.org/modules/translation"
|
|
|
|
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
|
)
|
|
|
|
// Status represents the status of ActionRun, ActionRunJob, ActionTask, or ActionTaskStep
|
|
type Status int
|
|
|
|
const (
|
|
StatusUnknown Status = iota // 0, consistent with runnerv1.Result_RESULT_UNSPECIFIED
|
|
StatusSuccess // 1, consistent with runnerv1.Result_RESULT_SUCCESS
|
|
StatusFailure // 2, consistent with runnerv1.Result_RESULT_FAILURE
|
|
StatusCancelled // 3, consistent with runnerv1.Result_RESULT_CANCELLED
|
|
StatusSkipped // 4, consistent with runnerv1.Result_RESULT_SKIPPED
|
|
StatusWaiting // 5, isn't a runnerv1.Result
|
|
StatusRunning // 6, isn't a runnerv1.Result
|
|
StatusBlocked // 7, isn't a runnerv1.Result
|
|
)
|
|
|
|
var statusNames = map[Status]string{
|
|
StatusUnknown: "unknown",
|
|
StatusWaiting: "waiting",
|
|
StatusRunning: "running",
|
|
StatusSuccess: "success",
|
|
StatusFailure: "failure",
|
|
StatusCancelled: "cancelled",
|
|
StatusSkipped: "skipped",
|
|
StatusBlocked: "blocked",
|
|
}
|
|
|
|
var nameToStatus = make(map[string]Status, len(statusNames))
|
|
|
|
func init() {
|
|
// Populate name to status lookup map
|
|
for status, name := range statusNames {
|
|
nameToStatus[name] = status
|
|
}
|
|
}
|
|
|
|
// String returns the string name of the Status
|
|
func (s Status) String() string {
|
|
return statusNames[s]
|
|
}
|
|
|
|
// LocaleString returns the locale string name of the Status
|
|
func (s Status) LocaleString(lang translation.Locale) string {
|
|
return lang.TrString("actions.status." + s.String())
|
|
}
|
|
|
|
// IsDone returns whether the Status is final
|
|
func (s Status) IsDone() bool {
|
|
return s.In(StatusSuccess, StatusFailure, StatusCancelled, StatusSkipped)
|
|
}
|
|
|
|
// HasRun returns whether the Status is a result of running
|
|
func (s Status) HasRun() bool {
|
|
return s.In(StatusSuccess, StatusFailure)
|
|
}
|
|
|
|
func (s Status) IsUnknown() bool {
|
|
return s == StatusUnknown
|
|
}
|
|
|
|
func (s Status) IsSuccess() bool {
|
|
return s == StatusSuccess
|
|
}
|
|
|
|
func (s Status) IsFailure() bool {
|
|
return s == StatusFailure
|
|
}
|
|
|
|
func (s Status) IsCancelled() bool {
|
|
return s == StatusCancelled
|
|
}
|
|
|
|
func (s Status) IsSkipped() bool {
|
|
return s == StatusSkipped
|
|
}
|
|
|
|
func (s Status) IsWaiting() bool {
|
|
return s == StatusWaiting
|
|
}
|
|
|
|
func (s Status) IsRunning() bool {
|
|
return s == StatusRunning
|
|
}
|
|
|
|
func (s Status) IsBlocked() bool {
|
|
return s == StatusBlocked
|
|
}
|
|
|
|
// In returns whether s is one of the given statuses
|
|
func (s Status) In(statuses ...Status) bool {
|
|
for _, v := range statuses {
|
|
if s == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (s Status) AsResult() runnerv1.Result {
|
|
if s.IsDone() {
|
|
return runnerv1.Result(s)
|
|
}
|
|
return runnerv1.Result_RESULT_UNSPECIFIED
|
|
}
|
|
|
|
func StatusFromString(name string) (Status, bool) {
|
|
status, exists := nameToStatus[name]
|
|
return status, exists
|
|
}
|