-
Notifications
You must be signed in to change notification settings - Fork 0
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
2ac946b
commit fd2197f
Showing
8 changed files
with
169 additions
and
14 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 - present, Ataberk Canitez | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,28 @@ | ||
# pr-links | ||
### GitHub CLI Pull Request Viewer | ||
|
||
pr-links is a command-line tool written in Go that enhances the functionality of the GitHub CLI by displaying Pull Request information along with their URLs. The GitHub CLI itself lacks the ability to show the Pull Request URL, and this tool bridges that gap. | ||
|
||
### Installation | ||
|
||
|
||
### Example Output | ||
|
||
The tool fetches open Pull Requests that are currently assigned to you and presents them in a formatted table. The table includes columns for the repository name, Pull Request ID, truncated title, and a direct link to the Pull Request on GitHub. | ||
![example-output](assets/example-output.png) | ||
|
||
### License | ||
This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details. | ||
|
||
|
||
### Acknowledgments | ||
|
||
- GitHub CLI for providing the foundation for interacting with GitHub from the command line. | ||
- alexeyco/simpletable for simplifying the creation of formatted tables in the console. | ||
|
||
### Contributing | ||
|
||
Feel free to contribute by opening issues or creating pull requests. Your feedback and involvement are highly encouraged! | ||
|
||
--- | ||
Enjoy using pr-links and feel free to reach out with any feedback or suggestions! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type GitHubService struct{} | ||
|
||
type PullRequest struct { | ||
Repo string | ||
Id string | ||
Status string | ||
Title string | ||
} | ||
|
||
func (gs *GitHubService) GetOpenPullRequests() ([]PullRequest, error) { | ||
cmd := exec.Command("gh", "search", "prs", "--review-requested", "@me", "--state", "open") | ||
output, err := cmd.Output() | ||
if err != nil { | ||
return nil, fmt.Errorf("error running git status: %v", err) | ||
} | ||
return parsePullRequests(string(output)), nil | ||
} | ||
|
||
func parsePullRequests(prLine string) []PullRequest { | ||
var prs []PullRequest | ||
scanner := bufio.NewScanner(strings.NewReader(prLine)) | ||
for scanner.Scan() { | ||
line := strings.Split(scanner.Text(), "\t") | ||
pr := PullRequest{ | ||
Repo: line[0], | ||
Id: line[1], | ||
Status: line[2], | ||
Title: line[3], | ||
} | ||
prs = append(prs, pr) | ||
} | ||
return prs | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/alexeyco/simpletable" | ||
"strings" | ||
) | ||
|
||
type CliOutputHandler struct{} | ||
|
||
func (co *CliOutputHandler) PrintPullRequests(prs []PullRequest) { | ||
table := simpletable.New() | ||
table.Header = prepareHeader() | ||
for _, row := range prs { | ||
link := prepareLink(row.Repo, row.Id) | ||
title := prepareTitle(row.Title) | ||
r := []*simpletable.Cell{ | ||
{Text: row.Repo}, | ||
{Text: row.Id}, | ||
{Text: title}, | ||
{Text: link}, | ||
} | ||
table.Body.Cells = append(table.Body.Cells, r) | ||
} | ||
table.SetStyle(simpletable.StyleUnicode) | ||
fmt.Println(table.String()) | ||
} | ||
|
||
func prepareHeader() *simpletable.Header { | ||
return &simpletable.Header{ | ||
Cells: []*simpletable.Cell{ | ||
{Align: simpletable.AlignCenter, Text: "REPO"}, | ||
{Align: simpletable.AlignCenter, Text: "ID"}, | ||
{Align: simpletable.AlignCenter, Text: "TITLE"}, | ||
{Align: simpletable.AlignCenter, Text: "LINK"}, | ||
}, | ||
} | ||
} | ||
|
||
func prepareLink(repo, id string) string { | ||
return fmt.Sprintf("https://www.github.com/%s/pull/%s", repo, id) | ||
} | ||
|
||
func prepareTitle(input string) string { | ||
const maxCharacters = 40 | ||
var result strings.Builder | ||
var count int | ||
words := strings.Fields(input) | ||
|
||
for _, word := range words { | ||
wordLen := len(word) | ||
if count+wordLen > maxCharacters { | ||
result.WriteString("\n") | ||
count = 0 | ||
} | ||
result.WriteString(word) | ||
result.WriteString(" ") | ||
count += wordLen + 1 | ||
} | ||
|
||
return result.String() | ||
} |