From a12d6c14de05c9f1b2d89c45198bd51e4c776a6b Mon Sep 17 00:00:00 2001 From: Deepak Mohanakrishnan Date: Sat, 22 Jan 2022 12:57:08 +0530 Subject: [PATCH] support for GHE repository --- README.md | 16 ++++++++++++++++ cmd/generate.go | 3 ++- cmd/root.go | 1 + cmd/validate.go | 3 ++- github/github.go | 13 ++++++++++--- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 06e2b1c..99f488f 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ # release-me + +Utility to validate and generate a release note from the PR title, `Release Note` comment section in the PR description. The `validate` can be used during the PR validation to check the PR have atleast one of labels to categorize this change to the generated release notes. + +## Validator + +Checks the existance of labels required for generating release notes + +### Valid labels + +```text +"breaking", "misc", "bug", "enhancement" +``` + +### Generator + +A release note is generated through fetching all the pull requests merged after the latest tag (release) of the repository. The release note is outputted to stdout. diff --git a/cmd/generate.go b/cmd/generate.go index 6f238f3..9a7be94 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -30,8 +30,9 @@ func init() { func generateReleaseNote(cmd *cobra.Command, args []string) { githubToken, _ := cmd.Flags().GetString("github-token") + githubV4Endpoint, _ := cmd.Flags().GetString("v4-endpoint") - client := github.New(githubToken) + client := github.New(githubToken, githubV4Endpoint) githubOwner, _ := cmd.Flags().GetString("github-owner") githubRepo, _ := cmd.Flags().GetString("github-repo") diff --git a/cmd/root.go b/cmd/root.go index 1d2b588..cdb4dc3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,6 +21,7 @@ func init() { rootCmd.PersistentFlags().String("github-owner", "", "the login field of a github user or organization") rootCmd.PersistentFlags().String("github-repo", "", "the name of the github repository") rootCmd.PersistentFlags().String("github-token", "", "github oauth token to authenticate with") + rootCmd.PersistentFlags().String("v4-endpoint", "", "the github enterprise graphQL API v4 endpoint") rootCmd.MarkFlagRequired("github-token") rootCmd.MarkFlagRequired("github-owner") diff --git a/cmd/validate.go b/cmd/validate.go index c09650a..e2cd116 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -26,8 +26,9 @@ func init() { func validate(cmd *cobra.Command, args []string) { githubToken, _ := cmd.Flags().GetString("github-token") + githubV4Endpoint, _ := cmd.Flags().GetString("v4-endpoint") - client := github.New(githubToken) + client := github.New(githubToken, githubV4Endpoint) githubOwner, _ := cmd.Flags().GetString("github-owner") githubRepo, _ := cmd.Flags().GetString("github-repo") diff --git a/github/github.go b/github/github.go index 5f7b178..6fd63a5 100644 --- a/github/github.go +++ b/github/github.go @@ -32,13 +32,20 @@ func (pr PullRequest) HasLabel(label string) bool { return false } -func New(token string) GitHub { +func New(token string, githubV4Endpoint string) GitHub { src := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, ) httpClient := oauth2.NewClient(context.Background(), src) - return GitHub{ - client: githubv4.NewClient(httpClient), + + if githubV4Endpoint == "" { + return GitHub{ + client: githubv4.NewClient(httpClient), + } + } else { + return GitHub{ + client: githubv4.NewEnterpriseClient(githubV4Endpoint, httpClient), + } } }