-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gh-prs): introduce pull-request based populator
- Loading branch information
1 parent
8d7b76e
commit e9a0d3f
Showing
5 changed files
with
112 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
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,68 @@ | ||
package github | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/cli/go-gh/v2/pkg/api" | ||
"golang.org/x/exp/slog" | ||
) | ||
|
||
type PullRequest struct { | ||
Title string | ||
Author string | ||
Number int | ||
} | ||
|
||
type pullRequestPopulator struct { | ||
fromRef string | ||
toRef string | ||
apiClient *api.RESTClient | ||
repoOwner string | ||
repoName string | ||
} | ||
|
||
func NewPullRequestPopulator(fromRef, toRef, repoOwner, repoName string) (*pullRequestPopulator, error) { | ||
apiClient, err := api.DefaultRESTClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &pullRequestPopulator{ | ||
fromRef, | ||
toRef, | ||
apiClient, | ||
repoOwner, | ||
repoName, | ||
}, nil | ||
} | ||
|
||
func (p *pullRequestPopulator) PullRequests(ctx context.Context) ([]PullRequest, error) { | ||
response := struct { | ||
Name string | ||
Body string | ||
}{} | ||
|
||
requestBody, err := json.Marshal(map[string]string{ | ||
"owner": p.repoOwner, | ||
"repo": p.repoName, | ||
"tag_name": p.toRef, | ||
"target_commitish": "main", // TODO: make this configurable | ||
"previous_tag_name": p.fromRef, | ||
}) | ||
if err != nil { | ||
return []PullRequest{}, err | ||
} | ||
|
||
err = p.apiClient.Post(fmt.Sprintf("repos/%s/%s/releases/generate-notes", p.repoOwner, p.repoName), bytes.NewBuffer(requestBody), &response) | ||
if err != nil { | ||
return []PullRequest{}, err | ||
} | ||
|
||
slog.Info("successfully fetched changelog from github") | ||
slog.Debug("here's the changelog provided by github", "changelog", response.Body) | ||
|
||
return []PullRequest{}, nil | ||
} |