commands

package
v0.0.0-...-558b3ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApproverCmd = &cobra.Command{
	Use:     "approver",
	Aliases: []string{"a"},
	Short:   "Show pending merge requests by user",
	Long:    "This displays a list of pending merge requests by user",
	Args:    cobra.ArbitraryArgs,
	Run: func(cmd *cobra.Command, userNames []string) {
		client := gitlab.NewClient(nil)

		pendingRequests, err := client.PendingRequests()
		if err != nil {
			fmt.Println("An error occured:", err)
			return
		}

		if len(userNames) == 0 {
			user, err := client.AuthenticatedUser()
			if err != nil {
				fmt.Println("An error occured:", err)
				return
			}
			userNames = append(userNames, user.Username)
		}

		filteredPendingRequests := []gitlab.PendingRequest{}
		for _, pr := range pendingRequests {
		filterUser:
			for _, approverName := range pr.ApproverNames() {
				for _, userName := range userNames {
					if approverName == userName {
						filteredPendingRequests = append(filteredPendingRequests, *pr)
						break filterUser
					}
				}
			}
		}

		fmt.Printf("%d Pending merge requests for approvers %v:\n\n", len(filteredPendingRequests), userNames)
		for _, pr := range filteredPendingRequests {
			fmt.Println(color.LightGray(pr.Request.Author.Username))
			fmt.Printf("[%v] %v\n", pr.Project.Name, pr.Color(pr.Request.Title))
			fmt.Println(pr.Request.WebURL)
			fmt.Println(color.LightGray(fmt.Sprintf("%10s", "Created:")), pr.HumanReadableCreatedAtDiff())
			fmt.Println(color.LightGray(fmt.Sprintf("%10s", "Updated:")), pr.HumanReadableUpdatedAtDiff())
			fmt.Println(color.LightGray(fmt.Sprintf("%10s", "Approvers:")), strings.Join(pr.ApproverNames(), ", "))
			fmt.Println()
		}
	},
}

ApproverCmd is exported

View Source
var OverviewCmd = &cobra.Command{
	Use:     "overview",
	Aliases: []string{"o"},
	Short:   "Show pending merge requests overview",
	Long:    "This displays a table by project and approver sorted by the most pending merge requests",
	Run: func(cmd *cobra.Command, args []string) {
		client := gitlab.NewClient(nil)

		pendingRequests, err := client.PendingRequests()
		if err != nil {
			fmt.Println("An error occured:", err)
			return
		}

		rankedProjects := rankProjectsByPendingRequests(pendingRequests)
		headers := []string{"Approver"}
		for _, h := range rankedProjects {
			headers = append(headers, h.name)
		}

		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader(headers)

		rankedApprovers := rankApproversByPendingRequests(pendingRequests)
		for _, a := range rankedApprovers {
			row := []string{a.username}
			for _, h := range rankedProjects {
				project, ok := a.projects.get(h.name)
				value := ""
				if ok {
					value = strconv.Itoa(project.value)
				}
				row = append(row, value)
			}
			table.Append(row)
		}

		table.Render()
	},
}

OverviewCmd is exported

View Source
var ProjectCmd = &cobra.Command{
	Use:     "project",
	Aliases: []string{"p"},
	Short:   "Show pending merge requests by project",
	Long:    "This displays a list of pending merge requests by project",
	Args:    cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, projectNames []string) {
		client := gitlab.NewClient(nil)

		pendingRequests, err := client.PendingRequests()
		if err != nil {
			fmt.Println("An error occured:", err)
			return
		}

		filteredPendingRequests := []gitlab.PendingRequest{}
		for _, pr := range pendingRequests {
			for _, p := range projectNames {
				if p == pr.Project.Name {
					filteredPendingRequests = append(filteredPendingRequests, *pr)
					break
				}
			}
		}

		fmt.Printf("%d Pending merge requests for projects %v:\n\n", len(filteredPendingRequests), projectNames)
		for _, pr := range filteredPendingRequests {
			fmt.Println(color.LightGray(pr.Request.Author.Username))
			fmt.Printf("[%v] %v\n", pr.Project.Name, pr.Color(pr.Request.Title))
			fmt.Println(pr.Request.WebURL)
			fmt.Println(color.LightGray(fmt.Sprintf("%10s", "Created:")), pr.HumanReadableCreatedAtDiff())
			fmt.Println(color.LightGray(fmt.Sprintf("%10s", "Updated:")), pr.HumanReadableUpdatedAtDiff())
			fmt.Println(color.LightGray(fmt.Sprintf("%10s", "Approvers:")), strings.Join(pr.ApproverNames(), ", "))
			fmt.Println()
		}
	},
}

ProjectCmd is exported

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL