Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 39bb99d

Browse files
author
Noah Hanjun Lee
authored
Enhance UI of commit (#128)
* Add author to Commit * Add author to commit in the Deploy tab * Add commit detail to changes * Fix the folder of detail
1 parent 81c1c50 commit 39bb99d

File tree

8 files changed

+124
-27
lines changed

8 files changed

+124
-27
lines changed

internal/pkg/github/mapper.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ func mapGithubPermToRepoPerm(perms map[string]bool) vo.RemoteRepoPerm {
5757
}
5858

5959
func mapGithubCommitToCommit(cm *github.RepositoryCommit) *vo.Commit {
60-
isPullRequest := false
61-
if cm.Commit.Author != nil && cm.Commit.Committer != nil {
62-
if *cm.Commit.Author.Name != *cm.Commit.Committer.Name {
63-
isPullRequest = true
60+
var author *vo.Author
61+
if cm.Author != nil && cm.Commit.Author != nil {
62+
author = &vo.Author{
63+
Login: *cm.Author.Login,
64+
AvatarURL: *cm.Author.AvatarURL,
65+
Date: *cm.Commit.Author.Date,
6466
}
6567
}
6668

6769
return &vo.Commit{
68-
SHA: *cm.SHA,
69-
Message: *cm.Commit.Message,
70-
IsPullRequest: isPullRequest,
71-
HTMLURL: *cm.HTMLURL,
70+
SHA: *cm.SHA,
71+
Message: *cm.Commit.Message,
72+
HTMLURL: *cm.HTMLURL,
73+
Author: author,
7274
}
7375
}
7476

openapi.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,15 @@ components:
15411541
type: boolean
15421542
html_url:
15431543
type: string
1544+
author:
1545+
type: object
1546+
properties:
1547+
login:
1548+
type: string
1549+
avatar_url:
1550+
type: string
1551+
date:
1552+
type: string
15441553
required:
15451554
- sha
15461555
- message

ui/src/apis/commit.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,37 @@ import { StatusCodes } from 'http-status-codes'
22

33
import { instance, headers } from './setting'
44
import { _fetch } from "./_base"
5-
import { Commit, Status, HttpNotFoundError, StatusState } from '../models'
5+
import { Commit, Author, Status, HttpNotFoundError, StatusState } from '../models'
66

77
interface CommitData {
88
sha: string
99
message: string
1010
is_pull_request: boolean
1111
html_url: string
12+
author?: {
13+
login: string
14+
avatar_url: string
15+
date: string
16+
}
1217
}
1318

1419
export const mapDataToCommit = (data: CommitData): Commit => {
20+
let author: Author | undefined
21+
22+
if (data.author) {
23+
author = {
24+
login: data.author.login,
25+
avatarUrl: data.author.avatar_url,
26+
date: new Date(data.author.date)
27+
}
28+
}
29+
1530
return {
1631
sha: data.sha,
1732
message: data.message,
1833
isPullRequest: data.is_pull_request,
1934
htmlUrl: data.html_url,
35+
author
2036
}
2137
}
2238

ui/src/components/DeployConfirm.tsx

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Form, Typography, Avatar, Button, Collapse, Timeline } from "antd"
22
import moment from "moment"
3+
import { useState } from "react"
34

45
import { Deployment, Commit } from "../models"
56
import DeploymentRefCode from "./DeploymentRefCode"
67
import DeploymentStatusSteps from "./DeploymentStatusSteps"
78

8-
const { Text } = Typography
9+
const { Paragraph, Text } = Typography
910
const { Panel } = Collapse
1011

1112
interface DeployConfirmProps {
@@ -119,19 +120,56 @@ function CommitChanges(props: CommitChangesProps): JSX.Element {
119120
if (props.changes.length === 0) {
120121
return <div>There are no commits.</div>
121122
}
123+
122124
return (
123125
<Timeline>
124126
{props.changes.slice(0, 10).map((change, idx) => {
125-
const style: React.CSSProperties = (idx === props.changes.length - 1) ? {height: 0} : {}
126-
// Omit lines after the first feedline.
127-
const message = change.message.split("\n", 1)[0]
128-
129-
return <Timeline.Item key={idx} color="gray" style={style}>
130-
<a href={change.htmlUrl} className="gitploy-link">
131-
{message.substr(0, 50)}
132-
</a>
127+
return <Timeline.Item key={idx} color="gray">
128+
<CommitChange commit={change} />
133129
</Timeline.Item>
134130
})}
135131
</Timeline>
136132
)
133+
}
134+
135+
interface CommitChangeProps {
136+
commit: Commit
137+
}
138+
139+
function CommitChange(props: CommitChangeProps): JSX.Element {
140+
const commit = props.commit
141+
const [message, description] = commit.message.split("\n\n", 2)
142+
143+
const [hide, setHide] = useState(true)
144+
145+
const onClickHide = () => {
146+
setHide(!hide)
147+
}
148+
149+
return (
150+
<span >
151+
<a href={commit.htmlUrl} className="gitploy-link"><strong>{message.substring(0, 50)}</strong></a>
152+
{(description) ?
153+
<Button size="small" type="text" onClick={onClickHide}>
154+
<Text className="gitploy-code" code>...</Text>
155+
</Button> :
156+
null}
157+
{/* Display the description of the commit. */}
158+
{(!hide) ?
159+
<Paragraph style={{margin: 0}}>
160+
<pre style={{marginBottom: 0}}>
161+
{description.split(/(\r\n)/g).map((line, idx) => {
162+
return (line !== "\r\n")? <Text key={idx}>{line}</Text> : <br/>
163+
})}
164+
</pre>
165+
</Paragraph> :
166+
null}
167+
<br />
168+
{(commit?.author) ?
169+
<span >
170+
<Text >&nbsp;<Avatar size="small" src={commit.author.avatarUrl} /> {commit.author.login}</Text> <Text >committed {moment(commit.author?.date).fromNow()}</Text>
171+
</span> :
172+
null}
173+
</span>
174+
)
137175
}

ui/src/components/DeployForm.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { useState } from "react"
2-
import { Form, Select, Radio, Button, Typography } from "antd"
2+
import { Form, Select, Radio, Button, Typography, Avatar } from "antd"
33

44
import { Branch, Commit, Tag, DeploymentType, Status, User, Env } from "../models"
55

66
import CreatableSelect, {Option as Op} from "./CreatableSelect"
77
import StatusStateIcon from "./StatusStateIcon"
88
import ApproversSelect from "./ApproversSelect"
9+
import moment from "moment"
910

1011
export type Option = Op
1112

@@ -136,9 +137,7 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
136137

137138
const mapCommitToOption = (commit: Commit) => {
138139
return {
139-
label: <span>
140-
<Text className="gitploy-code" code>{commit.sha.substring(0, 7)}</Text> - {commit.message}
141-
</span>,
140+
label: <CommitDecorator commit={commit}/>,
142141
value: commit.sha,
143142
} as Option
144143
}
@@ -276,4 +275,20 @@ export default function DeployForm(props: DeployFormProps): JSX.Element {
276275
</Form.Item>
277276
</Form>
278277
)
278+
}
279+
280+
interface CommitDecoratorProps {
281+
commit: Commit
282+
}
283+
284+
function CommitDecorator(props: CommitDecoratorProps): JSX.Element {
285+
return (
286+
<span>
287+
<Text className="gitploy-code" code>{props.commit.sha.substring(0, 7)}</Text> - <Text strong>{props.commit.message}</Text> <br/>
288+
{(props.commit?.author)?
289+
<span >
290+
&nbsp;<Text ><Avatar size="small" src={props.commit.author.avatarUrl} /> {props.commit.author.login}</Text> <Text >committed {moment(props.commit.author?.date).fromNow()}</Text>
291+
</span>: null}
292+
</span>
293+
)
279294
}

ui/src/models/Commit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ export default interface Commit {
33
message: string
44
isPullRequest: boolean
55
htmlUrl: string
6+
author?: Author
7+
}
8+
9+
export interface Author {
10+
login: string
11+
avatarUrl: string
12+
date: Date
613
}
714

815
export interface Status {

ui/src/models/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Deployment, {
66
DeploymentStatus,
77
} from "./Deployment"
88
import Config, { Env, EnvApproval } from "./Config"
9-
import Commit, { Status, StatusState } from "./Commit"
9+
import Commit, { Author, Status, StatusState } from "./Commit"
1010
import Branch from "./Branch"
1111
import Tag from "./Tag"
1212
import User, { ChatUser, RateLimit } from "./User"
@@ -34,6 +34,7 @@ export type {
3434
Env,
3535
EnvApproval,
3636
Commit,
37+
Author,
3738
Status,
3839
Branch,
3940
Tag,

vo/commit.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package vo
22

3+
import "time"
4+
35
type (
46
Commit struct {
5-
SHA string `json:"sha"`
6-
Message string `json:"message"`
7-
IsPullRequest bool `json:"is_pull_request"`
8-
HTMLURL string `json:"html_url"`
7+
SHA string `json:"sha"`
8+
Message string `json:"message"`
9+
IsPullRequest bool `json:"is_pull_request"`
10+
HTMLURL string `json:"html_url"`
11+
Author *Author `json:"author,omitempty"`
12+
}
13+
14+
Author struct {
15+
Login string `json:"login"`
16+
AvatarURL string `json:"avatar_url"`
17+
Date time.Time `json:"date"`
918
}
1019

1120
StatusState string

0 commit comments

Comments
 (0)