Skip to content

Add GPG check before commit message in repository table #1681

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

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 13 additions & 0 deletions models/gpg_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,16 @@ func ParseCommitsWithSignature(oldCommits *list.List) *list.List {
}
return newCommits
}

// ParseCommitsInfoWithSignature checks if signaute of commits info are corresponding to users gpg keys.
func ParseCommitsInfoWithSignature(oldCommitsInfo [][]interface{}) [][]interface{} {
newCommitsInfo := make([][]interface{}, len(oldCommitsInfo))
for i, ci := range oldCommitsInfo {
var verif *CommitVerification
if commit, ok := ci[1].(*git.Commit); ok {
verif = ParseCommitWithSignature(commit)
}
newCommitsInfo[i] = []interface{}{ci[0], ci[1], verif}
}
return newCommitsInfo
}
3 changes: 2 additions & 1 deletion routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ func renderDirectory(ctx *context.Context, treeLink string) {
}
entries.Sort()

ctx.Data["Files"], err = entries.GetCommitsInfo(ctx.Repo.Commit, ctx.Repo.TreePath)
files, err := entries.GetCommitsInfo(ctx.Repo.Commit, ctx.Repo.TreePath)
if err != nil {
ctx.Handle(500, "GetCommitsInfo", err)
return
}
ctx.Data["Files"] = models.ParseCommitsInfoWithSignature(files)

var readmeFile *git.Blob
for _, entry := range entries {
Expand Down
10 changes: 10 additions & 0 deletions templates/repo/view_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
{{range $item := .Files}}
{{$entry := index $item 0}}
{{$commit := index $item 1}}
{{$verification := index $item 2}}
<tr>
{{if $entry.IsSubModule}}
<td>
Expand Down Expand Up @@ -72,6 +73,15 @@
</td>
{{end}}
<td class="message collapsing has-emoji">
{{if $commit.Signature}}
<span class="isSigned {{if $verification.Verified}} isVerified {{end}}">
{{if $verification.Verified}}
<i title="{{$verification.Reason}}" class="lock green icon"></i>
{{else}}
<i title="{{$.i18n.Tr $verification.Reason}}" class="unlock icon isSigned"></i>
{{end}}
</span>
{{end}}
<a rel="nofollow" href="{{$.RepoLink}}/commit/{{$commit.ID}}">
{{RenderCommitMessage false $commit.Summary $.RepoLink $.Repository.ComposeMetas}}
</a>
Expand Down