Skip to content

Commit

Permalink
Merge pull request #900 from traPtitech/fix/commit-display
Browse files Browse the repository at this point in the history
commit表示に関する修正
  • Loading branch information
motoki317 authored Apr 18, 2024
2 parents b349f0e + 95ab2a2 commit 05d84de
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
19 changes: 13 additions & 6 deletions dashboard/src/components/templates/app/AppBranchResolution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { style } from '@macaron-css/core'
import { styled } from '@macaron-css/solid'
import { AiOutlineBranches } from 'solid-icons/ai'
import { type Component, For, Show } from 'solid-js'
import { type Application, DeployType } from '/@/api/neoshowcase/protobuf/gateway_pb'
import type { Application } from '/@/api/neoshowcase/protobuf/gateway_pb'
import { Button } from '/@/components/UI/Button'
import Code from '/@/components/UI/Code'
import JumpButton from '/@/components/UI/JumpButton'
import { ToolTip } from '/@/components/UI/ToolTip'
import { List } from '/@/components/templates/List'
import { type CommitsMap, systemInfo } from '/@/libs/api'
import { ApplicationState, deploymentState } from '/@/libs/application'
import { AppStatusIcon } from '/@/components/templates/app/AppStatusIcon'
import type { CommitsMap } from '/@/libs/api'
import { ApplicationState, errorCommit } from '/@/libs/application'
import { diffHuman, shortSha } from '/@/libs/format'
import { colorVars, textVars } from '/@/theme'

Expand Down Expand Up @@ -61,10 +61,17 @@ const AppBranchResolution: Component<{
const commit = () => props.commits?.[props.app.commit]
const commitDisplay = () => {
const c = commit()
const isErrorCommit = props.app.commit === errorCommit
const base = (
<DataRow>
<AiOutlineBranches />
<div>{`${props.app.refName}${shortSha(props.app.commit)}`}</div>
<AiOutlineBranches size={20} />
<DataRow>
{`${props.app.refName} → `}
<Show when={isErrorCommit} fallback={shortSha(props.app.commit)}>
<AppStatusIcon state={ApplicationState.Error} size={20} />
Error
</Show>
</DataRow>
</DataRow>
)
if (!c || !c.commitDate) {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createPromiseClient } from '@connectrpc/connect'
import { createConnectTransport } from '@connectrpc/connect-web'
import { cache, revalidate } from '@solidjs/router'
import AsyncLock from 'async-lock'
import { createResource, createSignal } from 'solid-js'
import { createResource } from 'solid-js'
import toast from 'solid-toast'
import { APIService } from '/@/api/neoshowcase/protobuf/gateway_connect'
import {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/libs/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const deploymentState = (app: Application): ApplicationState => {
return ApplicationState.Serving
}

const errorCommit = '0'.repeat(40)
export const errorCommit = '0'.repeat(40)

export const applicationState = (app: Application): ApplicationState => {
if (!app.running) {
Expand Down
8 changes: 7 additions & 1 deletion pkg/usecase/apiserver/repository_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apiserver
import (
"context"
"fmt"
"github.com/samber/lo"

"github.com/friendsofgo/errors"

Expand Down Expand Up @@ -93,7 +94,12 @@ func (s *Service) GetRepositories(ctx context.Context, scope GetRepoScope) ([]*d
}

func (s *Service) GetRepositoryCommits(ctx context.Context, hashes []string) ([]*domain.RepositoryCommit, error) {
return handleRepoError(s.commitRepo.GetCommits(ctx, hashes))
commits, err := s.commitRepo.GetCommits(ctx, hashes)
if err != nil {
return nil, err
}
commits = lo.Filter(commits, func(c *domain.RepositoryCommit, _ int) bool { return !c.Error })
return commits, nil
}

func (s *Service) GetRepository(ctx context.Context, id string) (*domain.Repository, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/usecase/commit-fetcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func (s *service) fetchLoop(ctx context.Context, fetcher <-chan queueItem) {
func (s *service) fetchOne(ctx context.Context, repositoryID string, hashes []string) error {
start := time.Now()

hashes = lo.Uniq(hashes)
// Filter out errored app hashes
hashes = lo.Filter(hashes, func(hash string, _ int) bool { return hash != domain.EmptyCommit })
hashes = lo.Uniq(hashes) // Make them unique just in case

// Check if we have already tried
recordedCommits, err := s.commitsRepo.GetCommits(ctx, hashes)
Expand Down
5 changes: 3 additions & 2 deletions pkg/usecase/repofetcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ func (r *service) updateApps(ctx context.Context, repo *domain.Repository, apps
var hashes []string
for _, app := range apps {
commit, ok := refToCommit[app.RefName]
if !ok {
if ok {
hashes = append(hashes, commit)
} else {
log.Errorf("failed to get resolve ref %v for app %v", app.RefName, app.ID)
commit = domain.EmptyCommit // Mark as empty commit to signal error
}
hashes = append(hashes, commit)

err = r.appRepo.UpdateApplication(ctx, app.ID, &domain.UpdateApplicationArgs{Commit: optional.From(commit)})
if err != nil {
Expand Down

0 comments on commit 05d84de

Please sign in to comment.