Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch action to use Github library #634

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion actions/alibaba-dragonwell-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"regexp"
"sort"

"github.com/google/go-github/v32/github"
"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down
2 changes: 1 addition & 1 deletion actions/amazon-corretto-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"os"
"regexp"

"github.com/google/go-github/v32/github"
"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down
2 changes: 1 addition & 1 deletion actions/clojure-tools-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"os"
"strings"

"github.com/google/go-github/v32/github"
"github.com/google/go-github/v43/github"
"github.com/paketo-buildpacks/pipeline-builder/actions"
"golang.org/x/oauth2"
)
Expand Down
70 changes: 44 additions & 26 deletions actions/draft-release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@
package main

import (
"bytes"
"context"
_ "embed"
"net/http"
"os"
"strconv"
"strings"

"fmt"
"io/ioutil"
"path/filepath"

"github.com/paketo-buildpacks/libpak/effect"
"github.com/google/go-github/v43/github"
"github.com/paketo-buildpacks/pipeline-builder/actions"
"github.com/paketo-buildpacks/pipeline-builder/drafts"
"golang.org/x/oauth2"
)

//go:embed "draft.template"
Expand All @@ -40,46 +45,59 @@ func main() {
panic(err)
}

err = drafter.BuildAndWriteReleaseToFileDraftFromTemplate(
filepath.Join(".", "body"), templateContents, payload)
buf := &bytes.Buffer{}
err = drafter.BuildAndWriteReleaseDraftFromTemplate(buf, templateContents, payload)
if err != nil {
panic(err)
}
body := buf.String()

name := payload.Release.Name
if payload.PrimaryBuildpack.Info.Name != "" {
name = fmt.Sprintf("%s %s", payload.PrimaryBuildpack.Info.Name, payload.Release.Name)
}

err = ioutil.WriteFile(filepath.Join(".", "name"), []byte(name), 0644)
fullRepo, found := os.LookupEnv("GITHUB_REPOSITORY")
if !found {
panic(fmt.Errorf("unable to find GITHUB_REPOSITORY"))
}

owner := strings.SplitN(fullRepo, "/", 2)[0]
repo := strings.SplitN(fullRepo, "/", 2)[1]
releaseId, err := strconv.ParseInt(payload.Release.ID, 10, 32)
if err != nil {
panic(err)
panic(fmt.Errorf("unable to parse %s\n%w", payload.Release.ID, err))
}

execution := effect.Execution{
Command: "gh",
Args: []string{
"api",
"--method", "PATCH",
fmt.Sprintf("/repos/:owner/:repo/releases/%s", payload.Release.ID),
"--field", fmt.Sprintf("tag_name=%s", payload.Release.Tag),
"--field", "name=@./name",
"--field", "body=@./body",
},
repoRelease := github.RepositoryRelease{
TagName: &payload.Release.Tag,
Name: &name,
Body: &body,
}
if _, dryRun := inputs["dry_run"]; dryRun {
bits, err := ioutil.ReadFile(filepath.Join(".", "body"))
if err != nil {
panic(err)
}

if _, dryRun := inputs["dry_run"]; dryRun {
fmt.Println("Title:", name)
fmt.Println("Body:", string(bits))
fmt.Println("Would execute:", execution)
fmt.Println("Body:", body)
fmt.Println("Would execute EditRelease with:")
fmt.Println(" ", owner)
fmt.Println(" ", repo)
fmt.Println(" ", releaseId)
fmt.Println(" ", repoRelease)
} else {
err = effect.NewExecutor().Execute(execution)
var c *http.Client
if s, ok := inputs["token"]; ok {
c = oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(&oauth2.Token{AccessToken: s}))
}
gh := github.NewClient(c)

gh.Repositories.EditRelease(
context.Background(),
owner,
repo,
releaseId,
&repoRelease)
if err != nil {
panic(fmt.Errorf("unable to execute %s\n%w", execution, err))
panic(fmt.Errorf("unable to execute EditRelease %s/%s/%d with %q\n%w", owner, repo, releaseId, repoRelease, err))
}
}
}
2 changes: 1 addition & 1 deletion actions/github-release-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"os"
"regexp"

"github.com/google/go-github/v32/github"
"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down
2 changes: 1 addition & 1 deletion actions/graalvm-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"sort"
"strings"

"github.com/google/go-github/v32/github"
"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down
2 changes: 1 addition & 1 deletion actions/ibm-semeru-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"regexp"
"strings"

"github.com/google/go-github/v32/github"
"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down
2 changes: 1 addition & 1 deletion actions/leiningen-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"net/http"
"os"

"github.com/google/go-github/v32/github"
"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down
2 changes: 1 addition & 1 deletion actions/rustup-init-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"net/http"
"os"

"github.com/google/go-github/v32/github"
"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/disiqueira/gotree v1.0.0
github.com/gocolly/colly v1.2.0
github.com/google/go-containerregistry v0.8.0
github.com/google/go-github/v32 v32.1.0
github.com/iancoleman/strcase v0.2.0
github.com/onsi/gomega v1.19.0
github.com/pelletier/go-toml v1.9.4
Expand Down Expand Up @@ -53,6 +52,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/go-github/v43 v43.0.0
github.com/google/go-querystring v1.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.3.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down
8 changes: 5 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edY
github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bradleyfalzon/ghinstallation/v2 v2.0.4/go.mod h1:B40qPqJxWE0jDZgOR1JmaMy+4AY1eBP+IByOvqyAKp0=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
Expand Down Expand Up @@ -388,6 +389,7 @@ github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5
github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -442,9 +444,9 @@ github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-containerregistry v0.8.0 h1:mtR24eN6rapCN+shds82qFEIWWmg64NPMuyCNT7/Ogc=
github.com/google/go-containerregistry v0.8.0/go.mod h1:wW5v71NHGnQyb4k+gSshjxidrC7lN33MdWEn+Mz9TsI=
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-github/v41 v41.0.0/go.mod h1:XgmCA5H323A9rtgExdTcnDkcqp6S30AVACCBDOonIxg=
github.com/google/go-github/v43 v43.0.0 h1:y+GL7LIsAIF2NZlJ46ZoC/D1W1ivZasT0lnWHMYPZ+U=
github.com/google/go-github/v43 v43.0.0/go.mod h1:ZkTvvmCXBvsfPpTHXnH/d2hP9Y0cTbvN9kr5xqyXOIc=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down