This repository has been archived by the owner on Feb 20, 2024. 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.
Merge pull request #12 from prithvijit-dasgupta/master
[Issue #1] List PR Feature
- Loading branch information
Showing
7 changed files
with
159 additions
and
5 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,47 @@ | ||
package list | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/thamaraiselvam/git-api-cli/cmd/service" | ||
"github.com/thamaraiselvam/git-api-cli/cmd/types" | ||
"github.com/thamaraiselvam/git-api-cli/cmd/util" | ||
) | ||
|
||
func init() { | ||
listCmd.AddCommand(prInfoCmd) | ||
} | ||
|
||
var prInfoCmd = &cobra.Command{ | ||
Use: "pr", | ||
Short: "list pull-requests of current user", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return fmt.Errorf("enter your name") | ||
} | ||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
client := service.CreateClient(fmt.Sprintf("/search/issues?q=type:pr+author:%%22%s%%22&sort=created&order=desc", args[0])) | ||
prList, err := client.GetPRList() | ||
if err != nil { | ||
_ = fmt.Errorf("%v", err) | ||
os.Exit(1) | ||
} | ||
|
||
displayPRList(prList) | ||
}, | ||
} | ||
|
||
//Generates Table to be displayeds | ||
func displayPRList(prList types.PRItemList) { | ||
table := util.CreateTable() | ||
table.SetHeader([]string{"Title", "URL", "State"}) | ||
for i := 0; i < len(prList.Items); i++ { | ||
table.Append([]string{prList.Items[i].Title, prList.Items[i].PullRequest.URL, prList.Items[i].State}) | ||
} | ||
table.Render() | ||
|
||
} |
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,15 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/olekukonko/tablewriter" | ||
) | ||
|
||
//CreateTable creates a pre-specified table style to be written in std-out | ||
func CreateTable() *tablewriter.Table { | ||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetRowSeparator(".") | ||
table.SetRowLine(true) | ||
return table | ||
} |
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,14 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateTable(t *testing.T) { | ||
t.Run("should return user information on valid request", func(t *testing.T) { | ||
var table = CreateTable() | ||
assert.NotNil(t, table) | ||
}) | ||
} |
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