本文整理汇总了Golang中github.com/salsaflow/salsaflow/errs.NewError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewError函数的具体用法?Golang NewError怎么用?Golang NewError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FinaliseRelease
func (tool *codeReviewTool) FinaliseRelease(v *version.Version) (action.Action, error) {
// Get a GitHub client.
config, err := LoadConfig()
if err != nil {
return nil, err
}
client := ghutil.NewClient(config.Token())
owner, repo, err := git.ParseUpstreamURL()
if err != nil {
return nil, err
}
// Get the relevant review milestone.
releaseString := v.BaseString()
task := fmt.Sprintf("Get GitHub review milestone for release %v", releaseString)
log.Run(task)
milestone, err := milestoneForVersion(config, owner, repo, v)
if err != nil {
return nil, errs.NewError(task, err)
}
if milestone == nil {
log.Warn(fmt.Sprintf(
"Weird, GitHub review milestone for release %v not found", releaseString))
return nil, nil
}
// Close the milestone unless there are some issues open.
task = fmt.Sprintf(
"Make sure the review milestone for release %v can be closed", releaseString)
if num := *milestone.OpenIssues; num != 0 {
return nil, errs.NewError(
task,
fmt.Errorf(
"review milestone for release %v cannot be closed: %v issue(s) open",
releaseString, num))
}
milestoneTask := fmt.Sprintf("Close GitHub review milestone for release %v", releaseString)
log.Run(milestoneTask)
milestone, _, err = client.Issues.EditMilestone(owner, repo, *milestone.Number, &github.Milestone{
State: github.String("closed"),
})
if err != nil {
return nil, errs.NewError(milestoneTask, err)
}
// Return a rollback function.
return action.ActionFunc(func() error {
log.Rollback(milestoneTask)
task := fmt.Sprintf("Reopen GitHub review milestone for release %v", releaseString)
_, _, err := client.Issues.EditMilestone(owner, repo, *milestone.Number, &github.Milestone{
State: github.String("open"),
})
if err != nil {
return errs.NewError(task, err)
}
return nil
}), nil
}
示例2: createMilestone
func createMilestone(
config Config,
owner string,
repo string,
v *version.Version,
) (*github.Milestone, action.Action, error) {
// Create the review milestone.
var (
title = milestoneTitle(v)
milestoneTask = fmt.Sprintf("Create GitHub review milestone '%v'", title)
client = ghutil.NewClient(config.Token())
)
log.Run(milestoneTask)
milestone, _, err := client.Issues.CreateMilestone(owner, repo, &github.Milestone{
Title: github.String(title),
})
if err != nil {
return nil, nil, errs.NewError(milestoneTask, err)
}
// Return a rollback function.
return milestone, action.ActionFunc(func() error {
log.Rollback(milestoneTask)
task := fmt.Sprintf("Delete GitHub review milestone '%v'", title)
_, err := client.Issues.DeleteMilestone(owner, repo, *milestone.Number)
if err != nil {
return errs.NewError(task, err)
}
return nil
}), nil
}
示例3: Start
func (item *item) Start() *errs.Error {
task := fmt.Sprintf("Mark Sprintly item %v as being in progress", item.Number)
// Check whether we are not finished already.
switch item.Status {
case sprintly.ItemStatusSomeday:
case sprintly.ItemStatusBacklog:
case sprintly.ItemStatusInProgress:
fallthrough
case sprintly.ItemStatusCompleted:
fallthrough
case sprintly.ItemStatusAccepted:
// Nothing to do.
return nil
}
// Load the Sprintly config.
config, err := LoadConfig()
if err != nil {
return errs.NewError(task, err)
}
// Instantiate the Sprintly client.
client := sprintly.NewClient(config.Username(), config.Token())
// Move the item to in-progress.
_, _, err = client.Items.Update(config.ProductId(), item.Number, &sprintly.ItemUpdateArgs{
Status: sprintly.ItemStatusInProgress,
})
if err != nil {
return errs.NewError(task, err)
}
return nil
}
示例4: SetAssignees
func (story *story) SetAssignees(users []common.User) error {
task := fmt.Sprintf("Set owners for story %v", story.Story.Id)
ownerIds := make([]int, len(users))
for i, user := range users {
id, err := strconv.Atoi(user.Id())
if err != nil {
return errs.NewError(task, err)
}
ownerIds[i] = id
}
var (
config = story.tracker.config
client = pivotal.NewClient(config.UserToken)
projectId = config.ProjectId
)
updateRequest := &pivotal.StoryRequest{OwnerIds: &ownerIds}
updatedStory, _, err := client.Stories.Update(projectId, story.Story.Id, updateRequest)
if err != nil {
return errs.NewError(task, err)
}
story.Story = updatedStory
return nil
}
示例5: ListTags
// ListTags returns the list of all release tags, sorted by the versions they represent.
func ListTags() (tags []string, err error) {
var task = "Get release tags"
// Get all release tags.
stdout, err := git.RunCommand("tag", "--list", "v*.*.*")
if err != nil {
return nil, errs.NewError(task, err)
}
// Parse the output to get sortable versions.
var vers []*version.Version
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
line := scanner.Text()
if line == "" {
continue
}
line = line[1:] // strip "v"
ver, _ := version.Parse(line)
vers = append(vers, ver)
}
if err := scanner.Err(); err != nil {
return nil, errs.NewError(task, err)
}
// Sort the versions.
sort.Sort(version.Versions(vers))
// Convert versions back to tag names and return.
tgs := make([]string, 0, len(vers))
for _, ver := range vers {
tgs = append(tgs, "v"+ver.String())
}
return tgs, nil
}
示例6: postUnassignedReviewRequest
// postUnassignedReviewRequest can be used to post the given commit for review.
// This function is to be used to post commits that are not associated with any story.
func postUnassignedReviewRequest(
config *moduleConfig,
owner string,
repo string,
commit *git.Commit,
opts map[string]interface{},
) (*github.Issue, []*git.Commit, error) {
// Search for an existing issue.
task := fmt.Sprintf("Search for an existing review issue for commit %v", commit.SHA)
log.Run(task)
client := ghutil.NewClient(config.Token)
issue, err := ghissues.FindReviewIssueForCommit(client, owner, repo, commit.SHA)
if err != nil {
return nil, nil, errs.NewError(task, err)
}
// Return an error in case the issue for the given commit already exists.
if issue != nil {
issueNum := *issue.Number
err = fmt.Errorf("existing review issue found for commit %v: %v", commit.SHA, issueNum)
return nil, nil, errs.NewError("Make sure the review issue can be created", err)
}
// Create a new unassigned review request.
issue, err = createUnassignedReviewRequest(config, owner, repo, commit, opts)
if err != nil {
return nil, nil, err
}
return issue, []*git.Commit{commit}, nil
}
示例7: CreateMilestone
func CreateMilestone(
client *github.Client,
owner string,
repo string,
title string,
) (*github.Milestone, action.Action, error) {
// Create the milestone.
milestoneTask := fmt.Sprintf("Create GitHub milestone '%v'", title)
log.Run(milestoneTask)
milestone, _, err := client.Issues.CreateMilestone(owner, repo, &github.Milestone{
Title: github.String(title),
})
if err != nil {
return nil, nil, errs.NewError(milestoneTask, err)
}
// Return a rollback function.
return milestone, action.ActionFunc(func() error {
log.Rollback(milestoneTask)
task := fmt.Sprintf("Delete GitHub milestone '%v'", title)
_, err := client.Issues.DeleteMilestone(owner, repo, *milestone.Number)
if err != nil {
return errs.NewError(task, err)
}
return nil
}), nil
}
示例8: getAndPourSkeleton
func getAndPourSkeleton(skeleton string) error {
// Get or update given skeleton.
task := fmt.Sprintf("Get or update skeleton '%v'", skeleton)
log.Run(task)
if err := getOrUpdateSkeleton(flagSkeleton); err != nil {
return errs.NewError(task, err)
}
// Move the skeleton files into place.
task = "Copy the skeleton into the configuration directory"
log.Go(task)
localConfigDir, err := config.LocalConfigDirectoryAbsolutePath()
if err != nil {
return errs.NewError(task, err)
}
log.NewLine("")
if err := pourSkeleton(flagSkeleton, localConfigDir); err != nil {
return errs.NewError(task, err)
}
log.NewLine("")
log.Ok(task)
return nil
}
示例9: Start
func (release *nextRelease) Start() (action.Action, error) {
var (
client = release.client
productId = release.tracker.config.ProductId()
itemReleaseTag = getItemReleaseTag(release.trunkVersion)
)
// Add the release tag to the relevant Sprintly items.
task := "Tag relevant items with the release tag"
log.Run(task)
items, err := addTag(client, productId, release.additionalItems, itemReleaseTag)
if err != nil {
return nil, errs.NewError(task, err)
}
release.additionalItems = nil
// Return the rollback action, which removes the release tags that were added.
return action.ActionFunc(func() error {
log.Rollback(task)
_, err := removeTag(client, productId, items, itemReleaseTag)
if err != nil {
return errs.NewError("Remove the release tag from relevant items", err, nil)
}
return nil
}), nil
}
示例10: CurrentUser
func (tracker *issueTracker) CurrentUser() (common.User, error) {
task := "Fetch the current user from Sprintly"
var (
productId = tracker.config.ProductId()
username = tracker.config.Username()
)
// Fetch all members of this product.
users, _, err := tracker.client.People.List(productId)
if err != nil {
return nil, errs.NewError(task, err)
}
// Find the user with matching username.
for _, usr := range users {
if usr.Email == username {
return &user{&usr}, nil
}
}
// In case there is no such user, they were not invited yet.
return nil, errs.NewError(
task, fmt.Errorf("user '%v' not a member of this product", username), nil)
}
示例11: doInstall
// doInstall performs the common step that both install and upgrade need to do.
//
// Given a GitHub release, it downloads and unpacks the fitting artifacts
// and replaces the current executables with the ones just downloaded.
func doInstall(
client *github.Client,
owner string,
repo string,
assets []github.ReleaseAsset,
version string,
dstDir string,
) (err error) {
// Choose the asset to be downloaded.
task := "Pick the most suitable release asset"
var (
assetName = getAssetName(version)
assetURL string
)
for _, asset := range assets {
if *asset.Name == assetName {
assetURL = *asset.BrowserDownloadURL
}
}
if assetURL == "" {
return errs.NewError(task, errors.New("no suitable release asset found"))
}
// Make sure the destination folder exists.
task = "Make sure the destination directory exists"
dstDir, act, err := ensureDstDirExists(dstDir)
if err != nil {
return errs.NewError(task, err)
}
defer action.RollbackOnError(&err, act)
// Download the selected release asset.
return downloadAndInstallAsset(assetName, assetURL, dstDir)
}
示例12: Start
// Start is a part of common.NextRelease interface.
func (release *nextRelease) Start() (act action.Action, err error) {
// In case there are no additional issues, we are done.
if len(release.additionalIssues) == 0 {
return action.Noop, nil
}
// Set milestone for the additional issues.
task := fmt.Sprintf(
"Set milestone to '%v' for the issues added automatically",
release.trunkVersion.BaseString())
log.Run(task)
// Get the milestone corresponding to the release branch version string.
chain := action.NewActionChain()
defer chain.RollbackOnError(&err)
milestone, act, err := release.tracker.getOrCreateMilestone(release.trunkVersion)
if err != nil {
return nil, errs.NewError(task, err)
}
chain.Push(act)
// Update the issues.
issues, act, err := release.tracker.updateIssues(
release.additionalIssues, setMilestone(milestone), unsetMilestone())
if err != nil {
return nil, errs.NewError(task, err)
}
chain.Push(act)
release.additionalIssues = issues
return chain, nil
}
示例13: promptUserToConfirmCommits
func promptUserToConfirmCommits(commits []*git.Commit) error {
// Make sure there are actually some commits to be posted.
task := "Make sure there are actually some commits to be posted"
if len(commits) == 0 {
return errs.NewError(task, ErrNoCommits)
}
// Tell the user what is going to happen.
fmt.Print(`
You are about to post some of the following commits for code review:
`)
mustListCommits(os.Stdout, commits, " ")
// Ask the user for confirmation.
task = "Prompt the user for confirmation"
confirmed, err := prompt.Confirm("\nYou cool with that?", true)
if err != nil {
return errs.NewError(task, err)
}
if !confirmed {
prompt.PanicCancel()
}
fmt.Println()
return nil
}
示例14: writeConfig
// WriteLocalConfig writes the given configuration struct
// into the local configuration file.
//
// In case the target path does not exist, it is created,
// including the parent directories.
//
// In case the file exists, it is truncated.
func writeConfig(absolutePath string, content interface{}, perm os.FileMode) error {
task := "Write a configuration file"
// Check the configuration directory and make sure it exists.
configDir := filepath.Dir(absolutePath)
info, err := os.Stat(configDir)
if err != nil {
if !os.IsNotExist(err) {
return errs.NewError(task, err)
}
// The directory doesn't exist.
if err := os.MkdirAll(configDir, 0750); err != nil {
return errs.NewError(task, err)
}
}
if !info.IsDir() {
return errs.NewError(task, errors.New("not a directory: "+configDir))
}
// Marshal the content.
raw, err := Marshal(content)
if err != nil {
return errs.NewError(task, err)
}
// Write the raw content into the file.
if err := ioutil.WriteFile(absolutePath, raw, perm); err != nil {
return errs.NewError(task, err)
}
return nil
}
示例15: createUnassignedReviewRequest
// createUnassignedReviewRequest created a new review issue
// for the given commit that is not associated with any story.
func createUnassignedReviewRequest(
config *moduleConfig,
owner string,
repo string,
commit *git.Commit,
opts map[string]interface{},
) (*github.Issue, error) {
task := fmt.Sprintf("Create review issue for commit %v", commit.SHA)
// Prepare the issue object.
reviewIssue := ghissues.NewCommitReviewIssue(commit.SHA, commit.MessageTitle)
// Get the right review milestone to add the issue into.
milestone, err := getOrCreateMilestoneForCommit(config, owner, repo, commit.SHA)
if err != nil {
return nil, errs.NewError(task, err)
}
// Create a new review issue.
issue, err := createIssue(
task, config, owner, repo,
reviewIssue.FormatTitle(), reviewIssue.FormatBody(),
optValueString(opts["reviewer"]), milestone, true)
if err != nil {
return nil, errs.NewError(task, err)
}
return issue, nil
}