gitea源码

api_pull_commits_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "net/http"
  6. "testing"
  7. issues_model "code.gitea.io/gitea/models/issues"
  8. repo_model "code.gitea.io/gitea/models/repo"
  9. "code.gitea.io/gitea/models/unittest"
  10. api "code.gitea.io/gitea/modules/structs"
  11. "code.gitea.io/gitea/tests"
  12. "github.com/stretchr/testify/assert"
  13. "github.com/stretchr/testify/require"
  14. )
  15. func TestAPIPullCommits(t *testing.T) {
  16. defer tests.PrepareTestEnv(t)()
  17. pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
  18. assert.NoError(t, pr.LoadIssue(t.Context()))
  19. repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pr.HeadRepoID})
  20. req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pr.Index)
  21. resp := MakeRequest(t, req, http.StatusOK)
  22. var commits []*api.Commit
  23. DecodeJSON(t, resp, &commits)
  24. require.Len(t, commits, 2)
  25. assert.Equal(t, "985f0301dba5e7b34be866819cd15ad3d8f508ee", commits[0].SHA)
  26. assert.Equal(t, "5c050d3b6d2db231ab1f64e324f1b6b9a0b181c2", commits[1].SHA)
  27. assert.NotEmpty(t, commits[0].Files)
  28. assert.NotEmpty(t, commits[1].Files)
  29. assert.NotNil(t, commits[0].RepoCommit.Verification)
  30. assert.NotNil(t, commits[1].RepoCommit.Verification)
  31. }
  32. // TODO add tests for already merged PR and closed PR