本文整理汇总了Golang中github.com/salsaflow/salsaflow/errs.NewError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewError函数的具体用法?Golang NewError怎么用?Golang NewError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:60,代码来源:code_review_tool.go
示例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
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:32,代码来源:code_review_tool.go
示例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
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:34,代码来源:item.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:25,代码来源:story.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:36,代码来源:git.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:34,代码来源:code_review_tool.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:28,代码来源:milestones.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:26,代码来源:command.go
示例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
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:26,代码来源:release_next.go
示例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)
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:25,代码来源:issue_tracker.go
示例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)
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:39,代码来源:common.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:34,代码来源:release_next.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:26,代码来源:common.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:39,代码来源:config.go
示例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
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:31,代码来源:code_review_tool.go
示例16: AddAssignee
func (item *item) AddAssignee(user common.User) *errs.Error {
task := "Assign the current user to the selected story"
// Load the Sprintly config.
config, err := LoadConfig()
if err != nil {
return errs.NewError(task, err)
}
// Parse the user ID.
userId, err := strconv.Atoi(user.Id())
if err != nil {
panic(err)
}
// Instantiate the Sprintly client.
client := sprintly.NewClient(config.Username(), config.Token())
// Assign the user to the selected story.
_, _, err = client.Items.Update(config.ProductId(), item.Number, &sprintly.ItemUpdateArgs{
AssignedTo: userId,
})
if err != nil {
return errs.NewError(task, err)
}
return nil
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:27,代码来源:item.go
示例17: EnsureDirectoryExists
func EnsureDirectoryExists(path string) (action.Action, error) {
// Check whether the directory exists already.
task := fmt.Sprintf("Check whether '%v' exists and is a directory", path)
info, err := os.Stat(path)
if err != nil {
if !os.IsNotExist(err) {
return nil, errs.NewError(task, err)
}
} else {
// In case the path exists, make sure it is a directory.
if !info.IsDir() {
return nil, errs.NewError(task, errors.New("not a directory: "+path))
}
// We are done.
return action.Noop, nil
}
// Now we know that path does not exist, so we need to create it.
createTask := fmt.Sprintf("Create directory '%v'", path)
log.Run(createTask)
if err := os.MkdirAll(path, 0755); err != nil {
return nil, errs.NewError(createTask, err)
}
return action.ActionFunc(func() error {
log.Rollback(createTask)
task := fmt.Sprintf("Remove directory '%v'", path)
if err := os.RemoveAll(path); err != nil {
return errs.NewError(task, err)
}
return nil
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:33,代码来源:directory.go
示例18: rebase
func rebase(currentBranch, parentBranch string) ([]*git.Commit, error) {
// Tell the user what is happening.
task := fmt.Sprintf("Rebase branch '%v' onto '%v'", currentBranch, parentBranch)
log.Run(task)
// Do the rebase.
if err := git.Rebase(parentBranch); err != nil {
ex := errs.Log(errs.NewError(task, err))
asciiart.PrintGrimReaper("GIT REBASE FAILED")
fmt.Printf(`Git failed to rebase your branch onto '%v'.
The repository might have been left in the middle of the rebase process.
In case you do not know how to handle this, just execute
$ git rebase --abort
to make your repository clean again.
In any case, you have to rebase your current branch onto '%v'
if you want to continue and post a review request. In the edge cases
you can as well use -no_rebase to skip this step, but try not to do it.
`, parentBranch, parentBranch)
return nil, ex
}
// Reload the commits.
task = "Get the commits to be posted for code review, again"
commits, err := git.ShowCommitRange(parentBranch + "..")
if err != nil {
return nil, errs.NewError(task, err)
}
// Return new commits.
return commits, nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:35,代码来源:mode_parent.go
示例19: Stage
func (release *runningRelease) Stage() (action.Action, error) {
var (
api = newClient(release.tracker.config)
versionString = release.releaseVersion.BaseString()
stageTask = fmt.Sprintf("Stage JIRA issues associated with release %v", versionString)
)
log.Run(stageTask)
// Make sure we only try to stage the issues that are in Tested.
var issuesToStage []*jira.Issue
for _, issue := range release.issues {
if issue.Fields.Status.Id == stateIdTested {
issuesToStage = append(issuesToStage, issue)
}
}
// Perform the transition.
err := performBulkTransition(api, issuesToStage, transitionIdStage, transitionIdUnstage)
if err != nil {
return nil, errs.NewError(stageTask, err)
}
return action.ActionFunc(func() error {
log.Rollback(stageTask)
unstageTask := fmt.Sprintf("Unstage JIRA issues associated with release %v", versionString)
if err := performBulkTransition(api, issuesToStage, transitionIdUnstage, ""); err != nil {
return errs.NewError(unstageTask, err)
}
return nil
}), nil
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:32,代码来源:release_running.go
示例20: PromptUserToConfirmStart
func (release *nextRelease) PromptUserToConfirmStart() (bool, error) {
// Collect the issues to be added to the current release.
task := "Collect the issues that modified trunk since the last release"
log.Run(task)
ids, err := releases.ListStoryIdsToBeAssigned(release.tracker)
if err != nil {
return false, errs.NewError(task, err)
}
// Fetch the additional issues from JIRA.
task = "Fetch the collected issues from JIRA"
log.Run(task)
issues, err := listStoriesById(newClient(release.tracker.config), ids)
if len(issues) == 0 && err != nil {
return false, errs.NewError(task, err)
}
if len(issues) != len(ids) {
log.Warn("Some issues were dropped since they were not found in JIRA")
}
// Drop the issues that were already assigned to the right version.
releaseLabel := release.trunkVersion.ReleaseTagString()
filteredIssues := make([]*jira.Issue, 0, len(issues))
IssueLoop:
for _, issue := range issues {
// Add only the parent tasks, i.e. skip sub-tasks.
if issue.Fields.Parent != nil {
continue
}
// Add only the issues that have not been assigned to the release yet.
for _, label := range issue.Fields.Labels {
if label == releaseLabel {
continue IssueLoop
}
}
filteredIssues = append(filteredIssues, issue)
}
issues = filteredIssues
// Present the issues to the user.
if len(issues) != 0 {
fmt.Println("\nThe following issues are going to be added to the release:\n")
err := prompt.ListStories(toCommonStories(issues, release.tracker), os.Stdout)
if err != nil {
return false, err
}
}
// Ask the user to confirm.
ok, err := prompt.Confirm(
fmt.Sprintf(
"\nAre you sure you want to start release %v?",
release.trunkVersion.BaseString()))
if err == nil {
release.additionalIssues = issues
}
return ok, err
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:58,代码来源:release_next.go
注:本文中的github.com/salsaflow/salsaflow/errs.NewError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论