improve user experience

pull/345/head
vapao 2021-07-12 16:18:58 +08:00
parent c26341d5a7
commit 65a316b0cd
2 changed files with 30 additions and 6 deletions

View File

@ -3,6 +3,7 @@
# Released under the AGPL-3.0 License. # Released under the AGPL-3.0 License.
from git import Repo, RemoteReference, TagReference, InvalidGitRepositoryError, GitCommandError from git import Repo, RemoteReference, TagReference, InvalidGitRepositoryError, GitCommandError
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from datetime import datetime
import shutil import shutil
import os import os
@ -31,12 +32,12 @@ class Git:
tags[ref.name] = { tags[ref.name] = {
'id': ref.tag.hexsha, 'id': ref.tag.hexsha,
'author': ref.tag.tagger.name, 'author': ref.tag.tagger.name,
'date': ref.tag.tagged_date, 'date': self._format_date(ref.tag.tagged_date),
'message': ref.tag.message.strip() 'message': ref.tag.message.strip()
} if ref.tag else { } if ref.tag else {
'id': ref.commit.binsha.hex(), 'id': ref.commit.binsha.hex(),
'author': ref.commit.author.name, 'author': ref.commit.author.name,
'date': ref.commit.authored_date, 'date': self._format_date(ref.commit.authored_date),
'message': ref.commit.message.strip() 'message': ref.commit.message.strip()
} }
tags = sorted(tags.items(), key=lambda x: x[1]['date'], reverse=True) tags = sorted(tags.items(), key=lambda x: x[1]['date'], reverse=True)
@ -77,11 +78,17 @@ class Git:
commits.append({ commits.append({
'id': commit.hexsha, 'id': commit.hexsha,
'author': commit.author.name, 'author': commit.author.name,
'date': commit.committed_date, 'date': self._format_date(commit.committed_date),
'message': commit.message.strip() 'message': commit.message.strip()
}) })
return commits return commits
def _format_date(self, timestamp):
if isinstance(timestamp, int):
date = datetime.fromtimestamp(timestamp)
return date.strftime('%Y-%m-%d %H:%M')
return timestamp
def __enter__(self): def __enter__(self):
if self.pkey: if self.pkey:
self.fd = NamedTemporaryFile() self.fd = NamedTemporaryFile()

View File

@ -136,7 +136,16 @@ export default observer(function () {
Object.keys(branches || {}).map(b => <Select.Option key={b} value={b}>{b}</Select.Option>) Object.keys(branches || {}).map(b => <Select.Option key={b} value={b}>{b}</Select.Option>)
) : ( ) : (
Object.entries(tags || {}).map(([tag, info]) => ( Object.entries(tags || {}).map(([tag, info]) => (
<Select.Option key={tag} value={tag}>{`${tag} ${info.author} ${info.message}`}</Select.Option> <Select.Option key={tag} value={tag}>
<div style={{display: 'flex', justifyContent: 'space-between'}}>
<span style={{
width: 200,
overflow: 'hidden',
textOverflow: 'ellipsis'
}}>{`${tag} ${info.author} ${info.message}`}</span>
<span style={{color: '#999', fontSize: 12}}>{info['date']} </span>
</div>
</Select.Option>
)) ))
)} )}
</Select> </Select>
@ -152,8 +161,16 @@ export default observer(function () {
<Form.Item required label="选择Commit ID"> <Form.Item required label="选择Commit ID">
<Select value={extra2} placeholder="请选择" onChange={v => setExtra2(v)}> <Select value={extra2} placeholder="请选择" onChange={v => setExtra2(v)}>
{extra1 && branches ? branches[extra1].map(item => ( {extra1 && branches ? branches[extra1].map(item => (
<Select.Option <Select.Option key={item.id}>
key={item.id}>{item.id.substr(0, 6)} {item['date']} {item['author']} {item['message']}</Select.Option> <div style={{display: 'flex', justifyContent: 'space-between'}}>
<span style={{
width: 400,
overflow: 'hidden',
textOverflow: 'ellipsis'
}}>{item.id.substr(0, 6)} {item['author']} {item['message']}</span>
<span style={{color: '#999', fontSize: 12}}>{item['date']} </span>
</div>
</Select.Option>
)) : null} )) : null}
</Select> </Select>
</Form.Item> </Form.Item>