Skip to content
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

Add status indicator on main home screen for each repo #24638

Merged
merged 23 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
45ff2c0
Add status indicator on main home screen for each repo
yardenshoham May 10, 2023
2279f7c
Update modules/structs/repo.go
yardenshoham May 10, 2023
62a589a
prefix `latest`
yardenshoham May 10, 2023
3a2722a
Don't touch the API
yardenshoham May 10, 2023
e414a41
Deduplicate code for svg selection
yardenshoham May 11, 2023
00717f6
Use `O(1)` database calls instead of `O(n)`
yardenshoham May 11, 2023
16643bc
Merge branch 'main' into issues/15620
yardenshoham May 11, 2023
0e7436e
Don't loop over branches, introduce `GetBranch`
yardenshoham May 11, 2023
0041c01
Update models/git/commit_status.go
yardenshoham May 11, 2023
e858179
Address some review comments from delvh
yardenshoham May 11, 2023
d1267e4
Send the entire status
yardenshoham May 11, 2023
e6d1a04
Merge branch 'main' into issues/15620
yardenshoham May 12, 2023
64f494f
Merge branch 'main' into issues/15620
yardenshoham May 12, 2023
fa57458
Merge branch 'main' into issues/15620
yardenshoham May 12, 2023
dc3f20a
Merge branch 'main' into issues/15620
yardenshoham May 12, 2023
927a3af
Parallelize `GetBranch` calls
yardenshoham May 13, 2023
44cc36c
Merge branch 'main' into issues/15620
yardenshoham May 13, 2023
52cd77e
Cut git calls in half
yardenshoham May 13, 2023
d37464b
Cut git calls in half again
yardenshoham May 13, 2023
7a22fcd
Merge branch 'main' into issues/15620
yardenshoham May 13, 2023
433df0b
Merge branch 'main' into issues/15620
GiteaBot May 13, 2023
2349e18
Merge branch 'main' into issues/15620
GiteaBot May 13, 2023
16bceb2
Merge branch 'main' into issues/15620
GiteaBot May 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,35 @@ type ExternalWiki struct {

// Repository represents a repository
type Repository struct {
ID int64 `json:"id"`
Owner *User `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description"`
Empty bool `json:"empty"`
Private bool `json:"private"`
Fork bool `json:"fork"`
Template bool `json:"template"`
Parent *Repository `json:"parent"`
Mirror bool `json:"mirror"`
Size int `json:"size"`
Language string `json:"language"`
LanguagesURL string `json:"languages_url"`
HTMLURL string `json:"html_url"`
Link string `json:"link"`
SSHURL string `json:"ssh_url"`
CloneURL string `json:"clone_url"`
OriginalURL string `json:"original_url"`
Website string `json:"website"`
Stars int `json:"stars_count"`
Forks int `json:"forks_count"`
Watchers int `json:"watchers_count"`
OpenIssues int `json:"open_issues_count"`
OpenPulls int `json:"open_pr_counter"`
Releases int `json:"release_counter"`
DefaultBranch string `json:"default_branch"`
Archived bool `json:"archived"`
ID int64 `json:"id"`
Owner *User `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description"`
Empty bool `json:"empty"`
Private bool `json:"private"`
Fork bool `json:"fork"`
Template bool `json:"template"`
Parent *Repository `json:"parent"`
Mirror bool `json:"mirror"`
Size int `json:"size"`
Language string `json:"language"`
LanguagesURL string `json:"languages_url"`
HTMLURL string `json:"html_url"`
Link string `json:"link"`
SSHURL string `json:"ssh_url"`
CloneURL string `json:"clone_url"`
OriginalURL string `json:"original_url"`
Website string `json:"website"`
Stars int `json:"stars_count"`
Forks int `json:"forks_count"`
Watchers int `json:"watchers_count"`
OpenIssues int `json:"open_issues_count"`
OpenPulls int `json:"open_pr_counter"`
Releases int `json:"release_counter"`
DefaultBranch string `json:"default_branch"`
LatestCommitStatusState CommitStatusState `json:"latest_commit_status_state"`
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
Archived bool `json:"archived"`
// swagger:strfmt date-time
Created time.Time `json:"created_at"`
// swagger:strfmt date-time
Expand Down
54 changes: 44 additions & 10 deletions routers/web/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
"code.gitea.io/gitea/models/organization"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
Expand Down Expand Up @@ -579,16 +580,17 @@ func SearchRepo(ctx *context.Context) {
results := make([]*api.Repository, len(repos))
for i, repo := range repos {
results[i] = &api.Repository{
ID: repo.ID,
FullName: repo.FullName(),
Fork: repo.IsFork,
Private: repo.IsPrivate,
Template: repo.IsTemplate,
Mirror: repo.IsMirror,
Stars: repo.NumStars,
HTMLURL: repo.HTMLURL(),
Link: repo.Link(),
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
ID: repo.ID,
FullName: repo.FullName(),
Fork: repo.IsFork,
Private: repo.IsPrivate,
Template: repo.IsTemplate,
Mirror: repo.IsMirror,
Stars: repo.NumStars,
HTMLURL: repo.HTMLURL(),
Link: repo.Link(),
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
LatestCommitStatusState: getLatestCommitStatusState(ctx, repo),
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -597,3 +599,35 @@ func SearchRepo(ctx *context.Context) {
Data: results,
})
}

// getLatestCommitStatusState returns the commit status state returns the latest commit status state of the latest
// commit on the default branch of the given repository
func getLatestCommitStatusState(ctx *context.Context, repo *repo_model.Repository) api.CommitStatusState {
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
branches, branchCount, _ := repo_service.GetBranches(ctx, repo, 0, 0)
if branchCount == 0 {
return ""
}

for _, branch := range branches {
// find the default branch
if repo.DefaultBranch == branch.Name {
commit, err := branch.GetCommit()
if err != nil {
log.Error("GetCommit: %v", err)
return ""
}

statuses, statusCount, err := git_model.GetLatestCommitStatus(ctx, repo.ID, commit.ID.String(), db.ListOptions{})
if err != nil {
log.Error("GetLatestCommitStatus: %v", err)
return ""
}
if statusCount == 0 {
return ""
}

return git_model.CalcCommitStatus(statuses).State
}
}
return ""
}
3 changes: 3 additions & 0 deletions templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions web_src/js/components/DashboardRepoList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@
<svg-icon name="octicon-archive" :size="16" class-name="gt-ml-2"/>
</span>
</div>
<!-- the commit status icon logic is taken from templates/repo/commit_status.tmpl -->
<svg-icon v-if="repo.latest_commit_status_state === 'pending'" name="octicon-dot-fill" class-name="commit-status icon text grey" :size="16"/>
<svg-icon v-else-if="repo.latest_commit_status_state === 'running'" name="octicon-dot-fill" class-name="commit-status icon text yellow" :size="16"/>
<svg-icon v-else-if="repo.latest_commit_status_state === 'success'" name="octicon-check" class-name="commit-status icon text green" :size="16"/>
<svg-icon v-else-if="repo.latest_commit_status_state === 'error'" name="gitea-exclamation" class-name="commit-status icon text red" :size="16"/>
<svg-icon v-else-if="repo.latest_commit_status_state === 'failure'" name="octicon-x" class-name="commit-status icon text red" :size="16"/>
<svg-icon v-else-if="repo.latest_commit_status_state === 'warning'" name="gitea-exclamation" class-name="commit-status icon text yellow" :size="16"/>
</a>
</li>
</ul>
Expand Down
6 changes: 6 additions & 0 deletions web_src/js/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {h} from 'vue';
import giteaDoubleChevronLeft from '../../public/img/svg/gitea-double-chevron-left.svg';
import giteaDoubleChevronRight from '../../public/img/svg/gitea-double-chevron-right.svg';
import giteaEmptyCheckbox from '../../public/img/svg/gitea-empty-checkbox.svg';
import giteaExclamation from '../../public/img/svg/gitea-exclamation.svg';
import octiconArchive from '../../public/img/svg/octicon-archive.svg';
import octiconArrowSwitch from '../../public/img/svg/octicon-arrow-switch.svg';
import octiconBlocked from '../../public/img/svg/octicon-blocked.svg';
import octiconBold from '../../public/img/svg/octicon-bold.svg';
import octiconCheck from '../../public/img/svg/octicon-check.svg';
import octiconCheckbox from '../../public/img/svg/octicon-checkbox.svg';
import octiconCheckCircleFill from '../../public/img/svg/octicon-check-circle-fill.svg';
import octiconChevronDown from '../../public/img/svg/octicon-chevron-down.svg';
Expand All @@ -19,6 +21,7 @@ import octiconDiffAdded from '../../public/img/svg/octicon-diff-added.svg';
import octiconDiffModified from '../../public/img/svg/octicon-diff-modified.svg';
import octiconDiffRemoved from '../../public/img/svg/octicon-diff-removed.svg';
import octiconDiffRenamed from '../../public/img/svg/octicon-diff-renamed.svg';
import octiconDotFill from '../../public/img/svg/octicon-dot-fill.svg';
import octiconEye from '../../public/img/svg/octicon-eye.svg';
import octiconFile from '../../public/img/svg/octicon-file.svg';
import octiconFileDirectoryFill from '../../public/img/svg/octicon-file-directory-fill.svg';
Expand Down Expand Up @@ -67,10 +70,12 @@ const svgs = {
'gitea-double-chevron-left': giteaDoubleChevronLeft,
'gitea-double-chevron-right': giteaDoubleChevronRight,
'gitea-empty-checkbox': giteaEmptyCheckbox,
'gitea-exclamation': giteaExclamation,
'octicon-archive': octiconArchive,
'octicon-arrow-switch': octiconArrowSwitch,
'octicon-blocked': octiconBlocked,
'octicon-bold': octiconBold,
'octicon-check': octiconCheck,
'octicon-check-circle-fill': octiconCheckCircleFill,
'octicon-checkbox': octiconCheckbox,
'octicon-chevron-down': octiconChevronDown,
Expand All @@ -84,6 +89,7 @@ const svgs = {
'octicon-diff-modified': octiconDiffModified,
'octicon-diff-removed': octiconDiffRemoved,
'octicon-diff-renamed': octiconDiffRenamed,
'octicon-dot-fill': octiconDotFill,
'octicon-eye': octiconEye,
'octicon-file': octiconFile,
'octicon-file-directory-fill': octiconFileDirectoryFill,
Expand Down