Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clickable commit link #1120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion components/commit/commit.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
+<span data-bind="text: numberOfAddedLines"></span>,
-<span data-bind="text: numberOfRemovedLines"></span>
|
<span data-bind="text: sha1.substr(0, 8)"></span>
<!-- ko if: commitLink() -->
<a data-bind="text: sha1.substr(0, 8), attr: { href: commitLink(), target: '_blank' }"></a>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click operation is being hijacked for in other components for handling node click and node unclicks. You would have to touch up on CommitViewModel.prototype.stopClickPropagation()

<!-- /ko -->
<!-- ko ifnot: commitLink() -->
<span data-bind="text: sha1.substr(0, 8)"></span>
<!-- /ko -->
</div>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions components/commit/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ function CommitViewModel(gitNode) {
this.authorDateFromNow = ko.observable();
this.authorName = ko.observable();
this.authorEmail = ko.observable();
this.commitLink = ko.computed(function() {
var short_sha1 = self.sha1.substr(0, 8);
var link_to_commit = ungit.config.linkToCommit[self.repoPath()]
if (link_to_commit != undefined) {
return ungit.config.linkToCommit[self.repoPath()].replace(/%h/g, short_sha1).replace(/%H/g, self.sha1)
}
else {
return null
}
});
this.fileLineDiffs = ko.observable();
this.numberOfAddedLines = ko.observable();
this.numberOfRemovedLines = ko.observable();
Expand Down
3 changes: 3 additions & 0 deletions source/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ const defaultConfig = {

// a string of ip to bind to, default is `127.0.0.1`
ungitBindIp: '127.0.0.1',

// example { "/home/projects/ungit" : "https://github.com/FredrikNoren/ungit/commit/%H" } use %H for full commit hash and %h for short commit hash
linkToCommit: {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should need to do this, we could just extract from the remote repo location right?

from there we can derive the url path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we can't, one repo may have many remotes (ie. one for github and one for heroku) so we can't decide which one win over the other. And some remotes can be privates (ie. git.example.com) and we can't derive the url path

Copy link
Collaborator

@jung-kim jung-kim Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea, you are absolutely right. but I bet most repos have single remote and conjunction with this map override method, it would be much better user experience

};

// Works for now but should be moved to bin/ungit
Expand Down