Woodpecker Plugin for creating netlify previews on PRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
958 B

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,
})
}