Categorygithub.com/kmesiab/go-github-diff
modulepackage
0.4.0
Repository: https://github.com/kmesiab/go-github-diff.git
Documentation: pkg.go.dev

# README

GitHub Pull Request Diff Library

Golang

Build Go Report Card

This Go library provides a set of functions to interact with GitHub Pull Requests, specifically for parsing and processing the contents of Git diffs associated with pull requests.

Features

  • Parse GitHub Pull Request URLs to extract owner, repository, and PR number.
  • Retrieve the contents of a Pull Request's Git diff from GitHub.
  • Parse combined Git diffs into individual file diffs.
  • Filter out file diffs based on a list of ignored file extensions.
  • Comprehensive regex-based file path matching for filtering file diffs.
  • Robust and extensive unit testing to ensure reliability and functionality.
  • Dependency injection support for GitHub API client, allowing for easier testing and flexibility.

Installation

To use this library, install it using go get:

go get github.com/kmesiab/go-github-diff

Usage

ParsePullRequestURL

prURL, err := github.ParsePullRequestURL(
    "https://github.com/username/repository/pull/123", 
)

if err != nil {
    // Handle error
}

// Use prURL.Owner, prURL.Repo, and prURL.PRNumber

GetPullRequestWithClient

// Create a new github client 
// (You can pass a HTTP Client, instead of nil)
client := github.NewClient(nil)

// Create a new GitHubClientWrapper using the github client
ghClient := ghdiff.GitHubClientWrapper{Client: client}

// Process the pull request using the new function
prString, err := ghdiff.GetPullRequestWithClient(context.TODO(), prURL, &ghClient)

if err != nil {
    fmt.Printf("Error getting pull request: %s\n", err)
    return
}

// Use diff as a string containing the Git diff

ParseGitDiff

diff := "..." // Git diff string
ignoreList := []string{".md", ".txt"}
gitDiffs := github.ParseGitDiff(diff, ignoreList)
for _, gitDiff := range gitDiffs {
// Process each gitDiff
}

Contributing

Contributions to this library are welcome! Here's how you can contribute:

Forking the Repository

  1. Go to the GitHub repository page: [GitHub Repository URL]

  2. Click on the 'Fork' button at the top right corner of the page. This creates a copy of the repository in your GitHub account.

  3. Clone the forked repository to your local machine:

    git clone https://github.com/yourusername/reponame.git
    
  4. Navigate to the cloned directory:

    cd reponame
    

Making Changes and Contributing

  1. Create a new branch for your changes:

    git checkout -b feature-branch-name
    
  2. Make your changes in the new branch. Be sure to follow the project's coding standards and guidelines.

  3. Commit your changes with a descriptive message:

    git commit -am "Add a brief description of your changes"
    
  4. Push the changes to your fork:

    git push origin feature-branch-name
    
  5. Go to your forked repository on GitHub, and click 'New Pull Request'.

  6. Ensure the 'base fork' points to the original repository, and the 'head fork' points to your fork.

  7. Provide a clear and detailed description of your changes in the pull request. Reference any related issues.

  8. Click 'Create Pull Request' to submit your changes for review.

After Your Pull Request

  • Wait for feedback or approval from the repository maintainers.
  • If requested, make any necessary updates to your pull request.
  • Once your pull request is merged, you can pull the changes from the original repository to keep your fork up to date.

Thank you for your contributions!

# Packages

No description provided by the author

# Functions

Deprecated: Use GetPullRequestWithClient or GetPullRequestFromGithub instead.
GetPullRequestFromGithub retrieves the contents of a pull request's Git diff from GitHub using the default client.
GetPullRequestWithClient retrieves the contents of a pull request's Git diff from GitHub using an injected client.
GetPullRequestWithDetails retrieves detailed information about a specific pull request from GitHub.
ParseGitDiff takes a string representing a combined Git diff and a list of file extensions to ignore.
ParsePullRequestURL parses a GitHub pull request URL and returns the owner, repository, and pull request number.

# Structs

No description provided by the author
GitHubClientWrapper is a wrapper around the official GitHub client provided by the go-github library.
MockGitClient is a mock implementation of the GitHubClientInterface, intended for use in unit tests.
No description provided by the author

# Interfaces

GitHubClientInterface defines an interface for interacting with GitHub, specifically for retrieving pull requests.