This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,190 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import yubikiri from 'yubikiri'; | ||
|
||
import ObserveModel from '../views/observe-model'; | ||
import LoadingView from '../views/loading-view'; | ||
import CommitDetailController from '../controllers/commit-detail-controller'; | ||
|
||
export default class CommitDetailContainer extends React.Component { | ||
static propTypes = { | ||
repository: PropTypes.object.isRequired, | ||
sha: PropTypes.string.isRequired, | ||
} | ||
|
||
fetchData = repository => { | ||
return yubikiri({ | ||
commit: repository.getCommit(this.props.sha), | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<ObserveModel model={this.props.repository} fetchData={this.fetchData}> | ||
{this.renderResult} | ||
</ObserveModel> | ||
); | ||
} | ||
|
||
renderResult = data => { | ||
if (this.props.repository.isLoading() || data === null || !data.commit.isPresent()) { | ||
return <LoadingView />; | ||
} | ||
|
||
return ( | ||
<CommitDetailController | ||
{...data} | ||
{...this.props} | ||
/> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {emojify} from 'node-emoji'; | ||
import moment from 'moment'; | ||
|
||
import MultiFilePatchController from './multi-file-patch-controller'; | ||
|
||
const avatarAltText = 'committer avatar'; | ||
|
||
export default class CommitDetailController extends React.Component { | ||
static propTypes = { | ||
repository: PropTypes.object.isRequired, | ||
|
||
workspace: PropTypes.object.isRequired, | ||
commands: PropTypes.object.isRequired, | ||
keymaps: PropTypes.object.isRequired, | ||
tooltips: PropTypes.object.isRequired, | ||
config: PropTypes.object.isRequired, | ||
|
||
destroy: PropTypes.func.isRequired, | ||
commit: PropTypes.object.isRequired, | ||
} | ||
|
||
render() { | ||
const commit = this.props.commit; | ||
// const {messageHeadline, messageBody, abbreviatedOid, url} = this.props.item; | ||
// const {avatarUrl, name, date} = this.props.item.committer; | ||
|
||
return ( | ||
<div className="github-CommitDetailView"> | ||
<div className="github-CommitDetailView-header"> | ||
<div className="github-CommitDetailView-commitContainer"> | ||
<div className="github-CommitDetailView-commit"> | ||
<h3 className="github-CommitDetailView-title"> | ||
{emojify(commit.getMessageSubject())} | ||
</h3> | ||
<pre className="github-CommitDetailView-moreText"> | ||
{emojify(commit.getMessageBody())}</pre> | ||
<div className="github-CommitDetailView-meta"> | ||
{/* TODO fix image src */} | ||
{this.renderAuthors()} | ||
<span className="github-CommitDetailView-metaText"> | ||
{commit.getAuthorEmail()} committed {this.humanizeTimeSince(commit.getAuthorDate())} | ||
</span> | ||
</div> | ||
</div> | ||
<div className="github-CommitDetailView-sha"> | ||
{/* TODO fix href */} | ||
<a href="https://github.com/atom/github/commit/6e0781600cccc3de2cc981f0d43209bf31cf86c8" | ||
title={`open commit ${commit.getSha()} on GitHub.com`}> | ||
{commit.getSha()} | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
<MultiFilePatchController | ||
multiFilePatch={commit.getMultiFileDiff()} | ||
autoHeight={false} | ||
{...this.props} | ||
disableStageUnstage={true} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
humanizeTimeSince(date) { | ||
return moment(date * 1000).fromNow(); | ||
} | ||
|
||
getAuthorInfo() { | ||
const coAuthorCount = this.props.commit.getCoAuthors().length; | ||
return coAuthorCount ? this.props.commit.getAuthorEmail() : `${coAuthorCount + 1} people`; | ||
} | ||
|
||
renderAuthor(email) { | ||
const match = email.match(/^(\d+)\+[^@]+@users.noreply.github.com$/); | ||
|
||
let avatarUrl; | ||
if (match) { | ||
avatarUrl = 'https://avatars.githubusercontent.com/u/' + match[1] + '?s=32'; | ||
} else { | ||
avatarUrl = 'https://avatars.githubusercontent.com/u/e?email=' + encodeURIComponent(email) + '&s=32'; | ||
} | ||
|
||
return ( | ||
<img className="github-RecentCommit-avatar" | ||
key={email} | ||
src={avatarUrl} | ||
title={email} | ||
alt={`${email}'s avatar'`} | ||
/> | ||
); | ||
} | ||
|
||
renderAuthors() { | ||
const coAuthorEmails = this.props.commit.getCoAuthors().map(author => author.email); | ||
const authorEmails = [this.props.commit.getAuthorEmail(), ...coAuthorEmails]; | ||
|
||
return ( | ||
<span className="github-RecentCommit-authors"> | ||
{authorEmails.map(this.renderAuthor)} | ||
</span> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.