-
-
Notifications
You must be signed in to change notification settings - Fork 800
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
1 parent
3140241
commit 3a58b6a
Showing
54 changed files
with
7,972 additions
and
219 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
title: "Gerrit" | ||
date: 2018-06-27T15:55:42-07:00 | ||
draft: false | ||
--- | ||
|
||
<img src="/imgs/modules/gerrit.png" width="640" height="384" alt="gerrit screenshot" /> | ||
|
||
Displays information about your projects hosted on Gerrit: | ||
|
||
#### Open Incoming Reviews | ||
|
||
All open reviews that are requesting your approval. | ||
|
||
#### My Outgoing Reviews | ||
|
||
All open reviews created by you. | ||
|
||
## Source Code | ||
|
||
```bash | ||
wtf/gerrit/ | ||
``` | ||
|
||
## Required ENV Variables | ||
|
||
<span class="caption">Key:</span> `WTF_GERRIT_PASSWORD` <br /> | ||
<span class="caption">Action:</span> Your <a href="https://gerrit-review.googlesource.com/Documentation/user-upload.html#http">Gerrit HTTP Password</a>. | ||
|
||
## Keyboard Commands | ||
|
||
<span class="caption">Key:</span> `/` <br /> | ||
<span class="caption">Action:</span> Open/close the widget's help window. | ||
|
||
<span class="caption">Key:</span> `h` <br /> | ||
<span class="caption">Action:</span> Show the previous project. | ||
|
||
<span class="caption">Key:</span> `l` <br /> | ||
<span class="caption">Action:</span> Show the next project. | ||
|
||
<span class="caption">Key:</span> `←` <br /> | ||
<span class="caption">Action:</span> Show the previous project. | ||
|
||
<span class="caption">Key:</span> `→` <br /> | ||
<span class="caption">Action:</span> Show the next project. | ||
|
||
## Configuration | ||
|
||
```yaml | ||
gerrit: | ||
enabled: true | ||
position: | ||
top: 2 | ||
left: 3 | ||
height: 2 | ||
width: 2 | ||
refreshInterval: 300 | ||
projects: | ||
- org/test-project" | ||
- dotfiles | ||
username: "myname" | ||
``` | ||
### Attributes | ||
`enabled` <br /> | ||
Determines whether or not this module is executed and if its data displayed onscreen. <br /> | ||
Values: `true`, `false`. | ||
|
||
`position` <br /> | ||
Defines where in the grid this module's widget will be displayed. <br /> | ||
|
||
`refreshInterval` <br /> | ||
How often, in seconds, this module will update its data. <br /> | ||
Values: A positive integer, `0..n`. | ||
|
||
`domain` <br /> | ||
_Optional_. Your Gerrit corporate domain. <br /> | ||
Values: A valid URI. | ||
|
||
`projects` <br /> | ||
A list of Gerrit project names to fetch data for. <br /> | ||
|
||
`username` <br /> | ||
Your Gerrit username. <br /> | ||
|
||
`verifyServerCertificate` <br /> | ||
_Optional_ <br /> | ||
Determines whether or not the server's certificate chain and host name are verified. <br /> | ||
Values: `true`, `false`. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package gerrit | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/senorprogrammer/wtf/wtf" | ||
) | ||
|
||
func (widget *Widget) display() { | ||
|
||
project := widget.currentGerritProject() | ||
if project == nil { | ||
fmt.Fprintf(widget.View, "%s", " Gerrit project data is unavailable (1)") | ||
return | ||
} | ||
|
||
widget.View.SetTitle(fmt.Sprintf("%s- %s", widget.Name, widget.title(project))) | ||
|
||
str := wtf.SigilStr(len(widget.GerritProjects), widget.Idx, widget.View) + "\n" | ||
str = str + " [red]Stats[white]\n" | ||
str = str + widget.displayStats(project) | ||
str = str + "\n" | ||
str = str + " [red]Open Incoming Reviews[white]\n" | ||
str = str + widget.displayMyIncomingReviews(project, wtf.Config.UString("wtf.mods.gerrit.username")) | ||
str = str + "\n" | ||
str = str + " [red]My Outgoing Reviews[white]\n" | ||
str = str + widget.displayMyOutgoingReviews(project, wtf.Config.UString("wtf.mods.gerrit.username")) | ||
|
||
widget.View.SetText(str) | ||
} | ||
|
||
func (widget *Widget) displayMyOutgoingReviews(project *GerritProject, username string) string { | ||
ors := project.myOutgoingReviews(username) | ||
|
||
if len(ors) == 0 { | ||
return " [grey]none[white]\n" | ||
} | ||
|
||
str := "" | ||
for _, r := range ors { | ||
str = str + fmt.Sprintf(" [green]%4s[white] %s\n", r.ChangeID, r.Subject) | ||
} | ||
|
||
return str | ||
} | ||
|
||
func (widget *Widget) displayMyIncomingReviews(project *GerritProject, username string) string { | ||
irs := project.myIncomingReviews(username) | ||
|
||
if len(irs) == 0 { | ||
return " [grey]none[white]\n" | ||
} | ||
|
||
str := "" | ||
for _, r := range irs { | ||
str = str + fmt.Sprintf(" [green]%4s[white] %s\n", r.ChangeID, r.Subject) | ||
} | ||
|
||
return str | ||
} | ||
|
||
func (widget *Widget) displayStats(project *GerritProject) string { | ||
str := fmt.Sprintf( | ||
" Reviews: %d\n", | ||
project.ReviewCount(), | ||
) | ||
|
||
return str | ||
} | ||
|
||
func (widget *Widget) title(project *GerritProject) string { | ||
return fmt.Sprintf("[green]%s [white]", project.Path) | ||
} |
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,100 @@ | ||
package gerrit | ||
|
||
import ( | ||
glb "github.com/andygrunwald/go-gerrit" | ||
) | ||
|
||
type GerritProject struct { | ||
gerrit *glb.Client | ||
Path string | ||
|
||
Changes *[]glb.ChangeInfo | ||
} | ||
|
||
func NewGerritProject(path string, gerrit *glb.Client) *GerritProject { | ||
project := GerritProject{ | ||
gerrit: gerrit, | ||
Path: path, | ||
} | ||
|
||
return &project | ||
} | ||
|
||
// Refresh reloads the gerrit data via the Gerrit API | ||
func (project *GerritProject) Refresh() { | ||
project.Changes, _ = project.loadChanges() | ||
} | ||
|
||
/* -------------------- Counts -------------------- */ | ||
|
||
func (project *GerritProject) IssueCount() int { | ||
if project.Changes == nil { | ||
return 0 | ||
} | ||
|
||
return len(*project.Changes) | ||
} | ||
|
||
func (project *GerritProject) ReviewCount() int { | ||
if project.Changes == nil { | ||
return 0 | ||
} | ||
|
||
return len(*project.Changes) | ||
} | ||
|
||
/* -------------------- Unexported Functions -------------------- */ | ||
|
||
// myOutgoingReviews returns a list of my outgoing reviews created by username on this project | ||
func (project *GerritProject) myOutgoingReviews(username string) []glb.ChangeInfo { | ||
changes := []glb.ChangeInfo{} | ||
|
||
if project.Changes == nil { | ||
return changes | ||
} | ||
|
||
for _, change := range *project.Changes { | ||
user := change.Owner | ||
|
||
if user.Username == username { | ||
changes = append(changes, change) | ||
} | ||
} | ||
|
||
return changes | ||
} | ||
|
||
// myIncomingReviews returns a list of merge requests for which username has been requested to ChangeInfo | ||
func (project *GerritProject) myIncomingReviews(username string) []glb.ChangeInfo { | ||
changes := []glb.ChangeInfo{} | ||
|
||
if project.Changes == nil { | ||
return changes | ||
} | ||
|
||
for _, change := range *project.Changes { | ||
reviewers := change.Reviewers | ||
|
||
for _, reviewer := range reviewers["REVIEWER"] { | ||
if reviewer.Username == username { | ||
changes = append(changes, change) | ||
} | ||
} | ||
} | ||
|
||
return changes | ||
} | ||
|
||
func (project *GerritProject) loadChanges() (*[]glb.ChangeInfo, error) { | ||
opt := &glb.QueryChangeOptions{} | ||
opt.Query = []string{"(projects:" + project.Path + "+ is:open + owner:self) " + " OR " + | ||
"(projects:" + project.Path + " + is:open + ((reviewer:self + -owner:self + -star:ignore) + OR + assignee:self))"} | ||
opt.AdditionalFields = []string{"DETAILED_LABELS", "DETAILED_ACCOUNTS"} | ||
changes, _, err := project.gerrit.Changes.QueryChanges(opt) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return changes, err | ||
} |
Oops, something went wrong.