woodpecker-netlify/netlify.go

32 lines
958 B
Go
Raw Permalink Normal View History

package main
import (
"context"
"fmt"
"os"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"github.com/gosimple/slug"
"github.com/netlify/open-api/v2/go/models"
"github.com/netlify/open-api/v2/go/porcelain"
ncontext "github.com/netlify/open-api/v2/go/porcelain/context"
)
func netlifyDeploy(netlifyAuthToken, netlifySiteID, buildDir string, prIndex int, prod bool) (*models.Deploy, error) {
ctx := ncontext.WithAuthInfo(context.Background(), runtime.ClientAuthInfoWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
return req.SetHeaderParam("Authorization", fmt.Sprintf("Bearer %s", netlifyAuthToken))
}))
netlifyClient := porcelain.Default
alias := fmt.Sprintf("%d-%s", prIndex, slug.Make(os.Getenv("DRONE_SOURCE_BRANCH")))
if prod {
alias = ""
}
return netlifyClient.DeploySite(ctx, porcelain.DeployOptions{
SiteID: netlifySiteID,
Dir: buildDir,
IsDraft: !prod,
Branch: alias,
})
}