You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Note, for this to work at least 1 commit is needed, so you if you use this
// after creating a repository you might want to make sure you set `AutoInit` to
// `true`.
package main
import (
"context"
"errors"
"flag"
"fmt"
"log"
"os"
"strings"
"time"
"github.com/google/go-github/v53/github"
)
var (
sourceOwner=flag.String("source-owner", "", "Name of the owner (user or org) of the repo to create the commit in.")
sourceRepo=flag.String("source-repo", "", "Name of repo to create the commit in.")
commitMessage=flag.String("commit-message", "", "Content of the commit message.")
commitBranch=flag.String("commit-branch", "", "Name of branch to create the commit in. If it does not already exists, it will be created using the `base-branch` parameter")
baseBranch=flag.String("base-branch", "master", "Name of branch to create the `commit-branch` from.")
prRepoOwner=flag.String("merge-repo-owner", "", "Name of the owner (user or org) of the repo to create the PR against. If not specified, the value of the `-source-owner` flag will be used.")
prRepo=flag.String("merge-repo", "", "Name of repo to create the PR against. If not specified, the value of the `-source-repo` flag will be used.")
prBranch=flag.String("merge-branch", "master", "Name of branch to create the PR against (the one you want to merge your branch in via the PR).")
prSubject=flag.String("pr-title", "", "Title of the pull request. If not specified, no pull request will be created.")
prDescription=flag.String("pr-text", "", "Text to put in the description of the pull request.")
sourceFiles=flag.String("files", "", `Comma-separated list of files to commit and their location.
The local file is separated by its target location by a semi-colon.
If the file should be in the same location with the same name, you can just put the file name and omit the repetition.
log.Fatal("You need to specify a non-empty value for the flags `-source-owner`, `-source-repo`, `-commit-branch`, `-files`, `-author-name` and `-author-email`")
}
client=github.NewTokenClient(ctx, token)
ref, err:=getRef()
iferr!=nil {
log.Fatalf("Unable to get/create the commit reference: %s\n", err)
}
ifref==nil {
log.Fatalf("No error where returned but the reference is nil")
}
tree, err:=getTree(ref)
iferr!=nil {
log.Fatalf("Unable to create the tree based on the provided files: %s\n", err)
}
iferr:=pushCommit(ref, tree); err!=nil {
log.Fatalf("Unable to create the commit: %s\n", err)
}
iferr:=createPR(); err!=nil {
log.Fatalf("Error while creating the pull request: %s", err)