pork

package module
v0.0.0-...-59866d8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 14 Imported by: 0

README

Pork

The Pork program, it's a CLI project that allows us to fork, PRs, search, read docs, clone, and many other functionalities from GitHub public accounts. This tool makes things easier for developers in order to find repositories and kind of automate development and integration processes

Dependencies

There's a lot of them

Check the glide.yaml file for it. For this project, we use four main dependencies.

  1. The NAP library (explained below) as the HTTP wrapper encapsulation for Rest API's interactions.
  2. Viper for handling configurations options for files. Check the library here
  3. Cobra is used for CLI apps generation. Check the library here
  4. gopkg.in/src-d/go-git.v4 this one is a Git implementation for Go. Check it here
NAP Library

NAP is a library that wraps up and interacts with the HTTP's Golang built-in package.

Creating GitHub API KEY

This process is quite easy, and it's very important because is the main window for GitHub interaction.

You should go to your GitHub Settings profile page first, then, check the Developer Settings, then move to the Personal Access tokens section and Generate new Token with public_repo and read:user. Grab the generated token and paste it the Pork.yaml

Filling pork.yaml file

The Pork.yaml (please rename it), contains the defaults for GitHub interaction, actually it holds two variables, the location (for repo interaction, things like: downloads and clones), and the main one which is the token.

This particular file serves as a secret file for holding our access credentials and environment setups.

You should rename the pork_example.yaml to pork.yaml and change the values for your own. It will be called many times by the os Golang package to

Usage

I assume you already have Go installed, with the GOPATH set.

Clone this repository inside your src directory and install it using the following command

go install ./cmd/...

Then, inside cmd/pork directory just, pork []

For help: pork -help

Commands

Clone functionality

The clone downloads a copy of a selecting repository to your local machine. The location is given by the location key set in the pork.yaml.

Internally expects 2 flags or sub-commands

  1. The --create flag: will create a reference if not found
  2. The --ref flag: will specify the branch name for the downloaded repository

Both of them are required

It's done like this: pork clone davidlares/arp-spoofing --create --ref master

Fork functionality

The fork command actually generates and reference a copy of a target repository into your Github account. This one uses the /repos/<OWNER>/<REPOSITORY>/forks API Endpoint.

This is done like this: pork fork yeyintminthuhtut/Awesome-Red-Teaming

Docs functionality

The docs command asks for README files using the /repos/<OWNER>/<REPOSITORY>/readme GitHub API endpoint. You will need to call this option like this

pork docs davidlares/arp-spoofing

PRs functionalities

We are also able to generate pull requests to any public repository. Internally creates a POST request to the /repos/<OWNER>/<PROJECT>/pulls GitHub API endpoint with certain values that points to the destination repository, the source repository a title and a message

Here's an example

pork pullrequest -d davidlares/arp-spoofing -t "This is my title" -m "This is my message" -s "davidlares:changes"

The source repository it's a combination of the owner:branch

Search functionality

The search command will actually send a query parameter to the /search/repositories?q=<YOUR-SEARCH-CRITERIA> GitHub API endpoint. This command will return a bunch of public repositories with the owner/repository format (actually it's a Go Slice element).

Here's an example of how to use it.

pork search infosec or pork search topic:infosec. Basically, anything that can be set up as a query criteria

Running tests

For doing this, check the go test -v command.

This will check and evaluate all the test files for the project, referenced by _test.go

Must of them will crash if you don't change the default values set in there. The current token value for many of the test files are previous API Keys that were used during development phases.

Credits

License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CloneCmd = &cobra.Command{
	Use:   "clone",
	Short: "Clone repository from GH",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) <= 0 {
			log.Fatalln("You must supply the repository")
		}
		if err := CloneRepository(args[0], ref, create); err != nil {
			log.Fatalln("error when closing repository: ", err)
		}
	},
}
View Source
var DocsCmd = &cobra.Command{
	Use:   "docs",
	Short: "Read the documentation for a repository",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) <= 0 {
			log.Fatalln("Invalid repository args")
		}
		if err := GetRepositoryReadme(args[0]); err != nil {
			log.Fatalln("Failed to get docs", err)
		}
	},
}
View Source
var ForkCmd = &cobra.Command{
	Use:   "fork",
	Short: "fork a Github repository",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) <= 0 {
			log.Fatalln("you must supply a repository")
		}
		if err := ForkRepository(args[0]); err != nil {
			log.Fatalln("unable to fork repository: ", err)
		}
	},
}
View Source
var PullRequestCmd = &cobra.Command{
	Use:   "pullrequest",
	Short: "Create a Pull Request",
	Run: func(cmd *cobra.Command, args []string) {
		if err := CreatePullRequest(); err != nil {
			log.Fatalln("Failed to create a pull request", err)
		}
	},
}
View Source
var SearchCmd = &cobra.Command{
	Use:   "search",
	Short: "Search for GH repos by keyword",
	Run: func(cmd *cobra.Command, args []string) {
		if err := SearchByKeyword(args); err != nil {
			log.Fatalln("Search failed: ", err)
		}
	},
}

Functions

func CloneRepository

func CloneRepository(repository, ref string, shouldCreate bool) error

func CreatePullRequest

func CreatePullRequest() error

func ForkRepository

func ForkRepository(repository string) error

fork functionality

func ForkSuccess

func ForkSuccess(resp *http.Response) error

success

func GetForkResource

func GetForkResource() *nap.RestResource

resource for the NAP library

func GetPullRequestResource

func GetPullRequestResource() *nap.RestResource

func GetReadmeResource

func GetReadmeResource() *nap.RestResource

func GetRepositoryReadme

func GetRepositoryReadme(repository string) error

func GetSearchResource

func GetSearchResource() *nap.RestResource

responses

func GitHubAPI

func GitHubAPI() *nap.API

singleton -> called and returns and object -> the same object is returned

func PullRequestDefaultRouter

func PullRequestDefaultRouter(resp *http.Response) error

func PullRequestSuccess

func PullRequestSuccess(resp *http.Response) error

func ReadmeDefaultRouter

func ReadmeDefaultRouter(resp *http.Response) error

func ReadmeSuccess

func ReadmeSuccess(resp *http.Response) error

func SearchByKeyword

func SearchByKeyword(keywords []string) error

func SearchDefaultRouter

func SearchDefaultRouter(resp *http.Response) error

check for code status

func SearchSuccess

func SearchSuccess(resp *http.Response) error

success response

Types

type ForkResponse

type ForkResponse struct {
	CloneURL string `json:"clone_url"`
	FullName string `json"full_name"`
}

type GHRepo

type GHRepo struct {
	RepoDir string
	// contains filtered or unexported fields
}

func NewGHRepo

func NewGHRepo(repository string) (*GHRepo, error)

func (*GHRepo) AddUpStream

func (g *GHRepo) AddUpStream(repository *GHRepo) error

remotes

func (*GHRepo) Checkout

func (g *GHRepo) Checkout(ref string, create bool) error

adding checkout

func (*GHRepo) Clone

func (g *GHRepo) Clone(dest string) error

expects a local disk destination

func (*GHRepo) RepositoryURL

func (g *GHRepo) RepositoryURL() string

this function will return the GH repository endpoint

type PullRequestPayload

type PullRequestPayload struct {
	Title        string `json:"title"`
	Message      string `json:"body"`
	SourceBranch string `json:"head"`
	DestBranch   string `json:"base"`
	Modify       bool   `json:"maintainer_can_modify"`
}

type PullRequestResponse

type PullRequestResponse struct {
	URL string `json:"html_url"`
}

type ReadResponse

type ReadResponse struct {
	Content string `json:"content"`
}

type SearchResponse

type SearchResponse struct {
	Results []*SearchResult `json:"items"` // return another slice
}

type SearchResult

type SearchResult struct {
	FullName string `json:"full_name"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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