Skip to content

Fix actions skipped commit status indicator #34507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
May 28, 2025

Conversation

badhezi
Copy link
Contributor

@badhezi badhezi commented May 20, 2025

Addresses #34500

Screenshot 2025-05-20 at 19 47 24

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 20, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/frontend labels May 20, 2025
@badhezi badhezi changed the title Dev/hezi/fix skipped icon Fix actions skipped commit status indicator May 20, 2025
@silverwind
Copy link
Member

Seems good, but I wonder whether the other two missing statuses from action model should also be represented in commit status. Currently "blocked" and "unknown" are missing:

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
)

Copy link
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change is LGMT but we should review the other two potential missing states later.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 22, 2025
Copy link
Contributor

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency maybe add add

// IsSkipped represents if commit status state is skipped
func (css CommitStatusState) IsSkipped() bool {
	return css == CommitStatusSkipped
}

@lunny
Copy link
Member

lunny commented May 25, 2025

Commit Status could have skipped, "pending", "success", "error", "failure", "warning"
but combined status should have only failure, pending and success.

Yes this sounds good, the Pullrequest UI only consumes the combined status, if the function combine would then convert skipped to success this should work.

-> I am not sure whether there is any problem in current implementation

Current implementation of Gitea main is good, new problems only appear due to skipped mapped to a new commitstatusskipped. As far I understood the code.

I don't think we can make IsSuccess behave like this. It introduces more ambiguity. skipped is skipped, not success.

Add IsSuccessOrSkipped and use it or inline are my other ideas here. AFAIK The suggestion from lunny would solve the UI part, the code part problem remains when doing that.

EDIT lunny your suggestion could make the commit summary render a green checkmark instead of skipped if everything is skipped.

Also replace IsSuccess with IsSuccessOrSkipped in the Pullrequest UI.

At least this seems to be not like just add a new commit status and everything works.

I sent #34531 to introduce the CombinedStatus concept.

@badhezi
Copy link
Contributor Author

badhezi commented May 27, 2025

@lunny / @ChristopherHX
Are there any additional changes needed for this PR?
If the current revision does not break any functionality and just resolves the skipped workflow indication, I suggest we merge this and continue work for CombinedStatus and other suggestions on a different issue.

@ChristopherHX
Copy link
Contributor

@badhezi Seems like my "regression" was not real

This test confirms your PR is fine, skipped never leaks to pull requests

func testAPICreateBranchProtectionWithRepo(t *testing.T, owner, repo, branchName string, body *api.BranchProtection, expectedHTTPStatus int) {
	token := getUserToken(t, "user2", auth_model.AccessTokenScopeWriteRepository)
	req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/branch_protections", owner, repo), body).
		AddTokenAuth(token)
	resp := MakeRequest(t, req, expectedHTTPStatus)

	if resp.Code == http.StatusOK {
		var branchProtection api.BranchProtection
		DecodeJSON(t, resp, &branchProtection)
		assert.Equal(t, branchName, branchProtection.RuleName)
	}
}

func TestMergePullRequestWithSkippedTest(t *testing.T) {
	onGiteaRun(t, func(t *testing.T, u *url.URL) {
		// user2 is the owner of the base repo
		user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
		user2Token := getTokenForLoggedInUser(t, loginUser(t, user2.Name), auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)

		// create the base repo
		apiBaseRepo := createActionsTestRepo(t, user2Token, "merge-pull-request-with-skipped", false)
		baseRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiBaseRepo.ID})
		user2APICtx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, auth_model.AccessTokenScopeWriteRepository)

		// init the workflow
		wfTreePath := ".gitea/workflows/pull.yml"
		wfFileContent := `name: Pull Request
on:
  pull_request:
jobs:
  echo:
    runs-on: ubuntu-latest
    if: 'false'
    steps:
      - run: echo 'Hello World'
`
		opts1 := getWorkflowCreateFileOptions(user2, baseRepo.DefaultBranch, "create "+wfTreePath, wfFileContent)
		createWorkflowFile(t, user2Token, baseRepo.OwnerName, baseRepo.Name, wfTreePath, opts1)

		// user4 creates a pull request to add file "app/main.go"
		doAPICreateFile(user2APICtx, "app/main.go", &api.CreateFileOptions{
			FileOptions: api.FileOptions{
				NewBranchName: "user4/add-main",
				Message:       "create main.go",
				Author: api.Identity{
					Name:  user2.Name,
					Email: user2.Email,
				},
				Committer: api.Identity{
					Name:  user2.Name,
					Email: user2.Email,
				},
				Dates: api.CommitDateOptions{
					Author:    time.Now(),
					Committer: time.Now(),
				},
			},
			ContentBase64: base64.StdEncoding.EncodeToString([]byte("// main.go")),
		})(t)
		apiPull, err := doAPICreatePullRequest(user2APICtx, baseRepo.OwnerName, baseRepo.Name, baseRepo.DefaultBranch, "user4/add-main")(t)
		assert.NoError(t, err)

		// enable status checks, require the "test1" check to pass
		testAPICreateBranchProtectionWithRepo(t, baseRepo.OwnerName, baseRepo.Name, baseRepo.DefaultBranch, &api.BranchProtection{
			BlockAdminMergeOverride: true,
			RuleName:                baseRepo.DefaultBranch,
			EnableStatusCheck:       true,
			StatusCheckContexts:     []string{"Pull Request / echo (pull_request)"},
		}, http.StatusCreated)

		runner := newMockRunner()
		runner.registerAsRepoRunner(t, user2.Name, baseRepo.Name, "mock-runner", []string{"ubuntu-latest"}, false)

		// TODO remove this once we have a way to skip jobs on Gitea side
		task := runner.fetchTask(t)
		runner.execTask(t, task, &mockTaskOutcome{
			result: runnerv1.Result_RESULT_SKIPPED,
		})

		doAPIMergePullRequest(user2APICtx, baseRepo.OwnerName, baseRepo.Name, apiPull.Index)(t)

		pullRequest := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: apiPull.ID})
		_ = pullRequest
	})
}

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 27, 2025
@wxiaoguang wxiaoguang force-pushed the dev/hezi/fix-skipped-icon branch from c35f9e4 to 8d78184 Compare May 27, 2025 19:41
@wxiaoguang wxiaoguang added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label May 28, 2025
@techknowlogick techknowlogick merged commit 0cec4b8 into go-gitea:main May 28, 2025
26 checks passed
@GiteaBot GiteaBot added this to the 1.25.0 milestone May 28, 2025
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants