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.
from git import Repo, RemoteReference, TagReference, InvalidGitRepositoryError, GitCommandError
from tempfile import NamedTemporaryFile
from datetime import datetime
import shutil
import os
@ -31,12 +32,12 @@ class Git:
tags[ref.name] = {
'id': ref.tag.hexsha,
'author': ref.tag.tagger.name,
'date': ref.tag.tagged_date,
'date': self._format_date(ref.tag.tagged_date),
'message': ref.tag.message.strip()
} if ref.tag else {
'id': ref.commit.binsha.hex(),
'author': ref.commit.author.name,
'date': ref.commit.authored_date,
'date': self._format_date(ref.commit.authored_date),
'message': ref.commit.message.strip()
}
tags = sorted(tags.items(), key=lambda x: x[1]['date'], reverse=True)
@ -77,11 +78,17 @@ class Git:
commits.append({
'id': commit.hexsha,
'author': commit.author.name,
'date': commit.committed_date,
'date': self._format_date(commit.committed_date),
'message': commit.message.strip()
})
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):
if self.pkey:
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.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>
@ -152,8 +161,16 @@ export default observer(function () {
<Form.Item required label="选择Commit ID">
<Select value={extra2} placeholder="请选择" onChange={v => setExtra2(v)}>
{extra1 && branches ? branches[extra1].map(item => (
<Select.Option
key={item.id}>{item.id.substr(0, 6)} {item['date']} {item['author']} {item['message']}</Select.Option>
<Select.Option key={item.id}>
<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}
</Select>
</Form.Item>