本文整理汇总了Golang中github.com/salsaflow/salsaflow/action.ActionFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang ActionFunc函数的具体用法?Golang ActionFunc怎么用?Golang ActionFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ActionFunc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: 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
示例4: Start
func (release *nextRelease) Start() (action.Action, error) {
// In case there are no additional stories, we are done.
if len(release.additionalStories) == 0 {
return action.Noop, nil
}
// Add release labels to the relevant stories.
var (
config = release.tracker.config
client = pivotal.NewClient(config.UserToken)
projectId = config.ProjectId
)
task := "Label the stories with the release label"
log.Run(task)
releaseLabel := getReleaseLabel(release.trunkVersion)
stories, err := addLabel(client, projectId,
release.additionalStories, releaseLabel)
if err != nil {
return nil, errs.NewError(task, err)
}
release.additionalStories = nil
// Return the rollback action, which removes the release labels that were appended.
return action.ActionFunc(func() error {
log.Rollback(task)
_, err := removeLabel(client, projectId, stories, releaseLabel)
if err != nil {
return errs.NewError("Remove the release label from the stories", err)
}
return nil
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:33,代码来源:release_next.go
示例5: 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
示例6: 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
示例7: 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
示例8: createBranch
func createBranch(branch, target string) (action.Action, error) {
// Create the branch.
if err := Branch(branch, target); err != nil {
return nil, err
}
return action.ActionFunc(func() error {
// On rollback, delete the branch.
return Branch("-D", branch)
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:11,代码来源:git.go
示例9: Stage
func (release *runningRelease) Stage() (action.Action, error) {
stageTask := fmt.Sprintf(
"Mark the stories as %v in Pivotal Tracker", pivotal.StoryStateDelivered)
log.Run(stageTask)
// Load the assigned stories.
stories, err := release.loadStories()
if err != nil {
return nil, errs.NewError(stageTask, err)
}
// Pick only the stories that are in the right state.
ss := make([]*pivotal.Story, 0, len(stories))
for _, s := range stories {
if release.tracker.canStoryBeStaged(s) {
ss = append(ss, s)
}
}
stories = ss
// Mark the selected stories as delivered. Leave the labels as they are.
updateRequest := &pivotal.StoryRequest{State: pivotal.StoryStateDelivered}
updateFunc := func(story *pivotal.Story) *pivotal.StoryRequest {
return updateRequest
}
// On rollback, set the story state to finished again.
rollbackFunc := func(story *pivotal.Story) *pivotal.StoryRequest {
return &pivotal.StoryRequest{State: pivotal.StoryStateFinished}
}
// Update the stories.
updatedStories, err := release.tracker.updateStories(stories, updateFunc, rollbackFunc)
if err != nil {
return nil, errs.NewError(stageTask, err)
}
release.stories = updatedStories
// Return the rollback function.
return action.ActionFunc(func() error {
// On error, set the states back to the original ones.
log.Rollback(stageTask)
task := fmt.Sprintf("Reset the story states back to %v", pivotal.StoryStateFinished)
updatedStories, err := release.tracker.updateStories(release.stories, rollbackFunc, nil)
if err != nil {
return errs.NewError(task, err)
}
release.stories = updatedStories
return nil
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:50,代码来源:release_running.go
示例10: resetBranch
func resetBranch(branch, target string) (action.Action, error) {
// Remember the current position.
current, err := Hexsha("refs/heads/" + branch)
if err != nil {
return nil, err
}
// Reset the branch.
if err := SetBranch(branch, target); err != nil {
return nil, err
}
return action.ActionFunc(func() error {
// On rollback, reset the branch to the original position.
return SetBranch(branch, current)
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:17,代码来源:git.go
示例11: Close
func (r *release) Close() (action.Action, error) {
// Make sure EnsureClosable has been called.
if r.closingMilestone == nil {
if err := r.EnsureClosable(); err != nil {
return nil, err
}
}
// Prepare for API calls.
client, owner, repo, err := r.prepareForApiCalls()
if err != nil {
return nil, err
}
// Close the milestone.
releaseString := r.v.BaseString()
milestoneTask := fmt.Sprintf("Close GitHub review milestone for release %v", releaseString)
log.Run(milestoneTask)
milestone, _, err := client.Issues.EditMilestone(
owner, repo, *r.closingMilestone.Number, &github.Milestone{
State: github.String("closed"),
})
if err != nil {
return nil, errs.NewError(milestoneTask, err)
}
r.closingMilestone = milestone
// Return a rollback function.
return action.ActionFunc(func() error {
log.Rollback(milestoneTask)
task := fmt.Sprintf("Reopen GitHub review milestone for release %v", releaseString)
milestone, _, err := client.Issues.EditMilestone(
owner, repo, *r.closingMilestone.Number, &github.Milestone{
State: github.String("open"),
})
if err != nil {
return errs.NewError(task, err)
}
r.closingMilestone = milestone
return nil
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:42,代码来源:release.go
示例12: MarkAsImplemented
func (story *story) MarkAsImplemented() (action.Action, error) {
// Make sure the story is started.
switch story.Story.State {
case pivotal.StoryStateStarted:
// Continue further to set the state to finished.
case pivotal.StoryStateFinished:
// Nothing to do here.
return nil, nil
default:
// Foobar, an unexpected story state encountered.
return nil, fmt.Errorf("unexpected story state: %v", story.State)
}
// Set the story state to finished.
var (
config = story.tracker.config
client = pivotal.NewClient(config.UserToken)
projectId = config.ProjectId
)
updateTask := fmt.Sprintf("Update Pivotal Tracker story (id = %v)", story.Story.Id)
updateRequest := &pivotal.StoryRequest{State: pivotal.StoryStateFinished}
updatedStory, _, err := client.Stories.Update(projectId, story.Story.Id, updateRequest)
if err != nil {
return nil, errs.NewError(updateTask, err)
}
originalStory := story.Story
story.Story = updatedStory
return action.ActionFunc(func() error {
log.Rollback(updateTask)
updateRequest := &pivotal.StoryRequest{State: originalStory.State}
updatedStory, _, err := client.Stories.Update(projectId, story.Story.Id, updateRequest)
if err != nil {
return err
}
story.Story = updatedStory
return nil
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:40,代码来源:story.go
示例13: ensureLocalConfigDirectoryExists
func ensureLocalConfigDirectoryExists() (action.Action, error) {
task := "Make sure the local configuration directory exists"
// Get the directory absolute path.
localConfigDir, err := config.LocalConfigDirectoryAbsolutePath()
if err != nil {
return nil, errs.NewError(task, err)
}
// In case the path exists, make sure it is a directory.
info, err := os.Stat(localConfigDir)
if err != nil {
if !os.IsNotExist(err) {
return nil, errs.NewError(task, err)
}
} else {
if !info.IsDir() {
return nil, errs.NewError(task, fmt.Errorf("not a directory: %v", localConfigDir))
}
return action.Noop, nil
}
// Otherwise create the directory.
if err := os.MkdirAll(localConfigDir, 0755); err != nil {
return nil, errs.NewError(task, err)
}
// Return the rollback function.
act := action.ActionFunc(func() error {
// Delete the directory.
log.Rollback(task)
task := "Delete the local configuration directory"
if err := os.RemoveAll(localConfigDir); err != nil {
return errs.NewError(task, err)
}
return nil
})
return act, nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:39,代码来源:command.go
示例14: CloseMilestone
func CloseMilestone(
client *github.Client,
owner string,
repo string,
milestone *github.Milestone,
) (*github.Milestone, action.Action, error) {
// Copy the milestone to have it stored locally for the rollback closure.
mstone := *milestone
// A helper closure.
setState := func(milestone *github.Milestone, state string) (*github.Milestone, error) {
task := fmt.Sprintf("Mark GitHub milestone '%v' as %v", *milestone.Title, state)
log.Run(task)
m, _, err := client.Issues.EditMilestone(owner, repo, *milestone.Number, &github.Milestone{
State: &state,
})
if err != nil {
return nil, errs.NewError(task, err)
}
return m, nil
}
// Close the chosen milestone.
m, err := setState(&mstone, "closed")
if err != nil {
return nil, nil, err
}
// Return the rollback function.
act := action.ActionFunc(func() error {
_, err := setState(&mstone, "open")
return err
})
return m, act, nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:36,代码来源:milestones.go
示例15: Stage
func Stage(options *StageOptions) (act action.Action, err error) {
// Rollback machinery.
chain := action.NewActionChain()
defer chain.RollbackOnError(&err)
// Make sure opts are not nil.
if options == nil {
options = DefaultStageOptions
}
// Load git config.
gitConfig, err := git.LoadConfig()
if err != nil {
return nil, err
}
var (
remoteName = gitConfig.RemoteName
releaseBranch = gitConfig.ReleaseBranchName
stagingBranch = gitConfig.StagingBranchName
)
// Instantiate the issue tracker.
tracker, err := modules.GetIssueTracker()
if err != nil {
return nil, err
}
// Get the current branch.
task := "Get the current branch"
currentBranch, err := gitutil.CurrentBranch()
if err != nil {
return nil, err
}
// Cannot be on the release branch, it will be deleted.
task = fmt.Sprintf("Make sure that branch '%v' is not checked out", releaseBranch)
if currentBranch == releaseBranch {
return nil, errs.NewError(
task, fmt.Errorf("cannot stage the release while on branch '%v'", releaseBranch))
}
// Fetch the remote repository.
if !options.SkipFetch {
task = "Fetch the remote repository"
log.Run(task)
if err := git.UpdateRemotes(remoteName); err != nil {
return nil, errs.NewError(task, err)
}
}
// Make sure that the local release branch exists and is up to date.
task = fmt.Sprintf("Make sure that branch '%v' is up to date", releaseBranch)
log.Run(task)
if err := git.CheckOrCreateTrackingBranch(releaseBranch, remoteName); err != nil {
return nil, errs.NewError(task, err)
}
// Read the current release version.
task = "Read the current release version"
releaseVersion, err := version.GetByBranch(releaseBranch)
if err != nil {
return nil, errs.NewError(task, err)
}
// Make sure the release is stageable.
release := tracker.RunningRelease(releaseVersion)
if err := release.EnsureStageable(); err != nil {
return nil, err
}
// Make sure there are no commits being left behind,
// e.g. make sure no commits are forgotten on the trunk branch,
// i.e. make sure that everything necessary was cherry-picked.
if err := checkCommits(tracker, release, releaseBranch); err != nil {
return nil, err
}
// Reset the staging branch to point to the newly created tag.
task = fmt.Sprintf("Reset branch '%v' to point to branch '%v'", stagingBranch, releaseBranch)
log.Run(task)
act, err = git.CreateOrResetBranch(stagingBranch, releaseBranch)
if err != nil {
return nil, errs.NewError(task, err)
}
chain.PushTask(task, act)
// Delete the local release branch.
task = fmt.Sprintf("Delete branch '%v'", releaseBranch)
log.Run(task)
if err := git.Branch("-D", releaseBranch); err != nil {
return nil, errs.NewError(task, err)
}
chain.PushTask(task, action.ActionFunc(func() error {
task := fmt.Sprintf("Recreate branch '%v'", releaseBranch)
// In case the release branch exists locally, do nothing.
// This might look like an extra and useless check, but it looks like
// the final git push at the end of the command function actually creates
// the release branch locally when it is aborted from the pre-push hook.
// Not sure why and how that is happening.
//.........这里部分代码省略.........
开发者ID:salsaflow,项目名称:salsaflow,代码行数:101,代码来源:stage.go
示例16: setStateLabel
func (s *story) setStateLabel(label string) (action.Action, error) {
// A helper function for setting issue labels.
setLabels := func(labels []string) error {
var (
client = s.tracker.newClient()
owner = s.tracker.config.GitHubOwner
repo = s.tracker.config.GitHubRepository
issueNum = *s.issue.Number
updatedLabels []github.Label
err error
)
withRequestAllocated(func() {
updatedLabels, _, err = client.Issues.ReplaceLabelsForIssue(
owner, repo, issueNum, labels)
})
if err != nil {
return err
}
s.issue.Labels = updatedLabels
return nil
}
// A helper function for appending label names.
appendLabelNames := func(names []string, labels []github.Label) []string {
for _, label := range labels {
names = append(names, *label.Name)
}
return names
}
// Set the state labels.
task := fmt.Sprintf("Set state label to '%v' for issue %v", label, s.ReadableId())
// Get the right label list.
otherLabels, prunedLabels := pruneStateLabels(s.tracker.config, s.issue.Labels)
newLabels := make([]string, 0, len(otherLabels)+1)
newLabels = appendLabelNames(newLabels, otherLabels)
newLabels = append(newLabels, label)
// Update the issue.
if err := setLabels(newLabels); err != nil {
return nil, errs.NewError(task, err)
}
// Return a rollback function.
return action.ActionFunc(func() error {
// Append the pruned labels.
newLabels := make([]string, 0, len(otherLabels)+len(prunedLabels))
newLabels = appendLabelNames(newLabels, prunedLabels)
// Generate the task string.
task := fmt.Sprintf("Set the state labels to [%v] for issue %v",
strings.Join(newLabels, ", "), s.ReadableId())
// Append the other labels as well, thus getting the original label list.
newLabels = appendLabelNames(newLabels, otherLabels)
// Update the issue.
if err := setLabels(newLabels); err != nil {
return errs.NewError(task, err)
}
return nil
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:65,代码来源:story.go
示例17: createBranch
//.........这里部分代码省略.........
line, err := prompt.Prompt(`
Please insert the branch slug now.
Insert an empty string to skip the branch creation step: `)
if err != nil && err != prompt.ErrCanceled {
return nil, errs.NewError(task, err)
}
sluggedLine := slug.Slug(line)
if sluggedLine == "" {
fmt.Println()
log.Log("Not creating any feature branch")
return nil, nil
}
branchName := "story/" + sluggedLine
ok, err := prompt.Confirm(
fmt.Sprintf(
"\nThe branch that is going to be created will be called '%s'.\nIs that alright?",
branchName),
true)
if err != nil {
return nil, errs.NewError(task, err)
}
if !ok {
panic(prompt.ErrCanceled)
}
fmt.Println()
createTask := fmt.Sprintf(
"Create branch '%v' on top of branch '%v'", branchName, baseBranch)
log.Run(createTask)
if err := git.Branch(branchName, baseBranch); err != nil {
return nil, errs.NewError(createTask, err)
}
deleteTask := fmt.Sprintf("Delete branch '%v'", branchName)
deleteBranch := func() error {
// Roll back and delete the newly created branch.
log.Rollback(createTask)
if err := git.Branch("-D", branchName); err != nil {
return errs.NewError(deleteTask, err)
}
return nil
}
// Checkout the newly created branch.
checkoutTask := fmt.Sprintf("Checkout branch '%v'", branchName)
log.Run(checkoutTask)
if err := git.Checkout(branchName); err != nil {
if err := deleteBranch(); err != nil {
errs.Log(err)
}
return nil, errs.NewError(checkoutTask, err)
}
// Push the newly created branch unless -no_push.
pushTask := fmt.Sprintf("Push branch '%v' to remote '%v'", branchName, remoteName)
if flagPush {
log.Run(pushTask)
if err := git.Push(remoteName, branchName); err != nil {
if err := deleteBranch(); err != nil {
errs.Log(err)
}
return nil, errs.NewError(pushTask, err)
}
}
return action.ActionFunc(func() error {
// Checkout the original branch.
log.Rollback(checkoutTask)
if err := git.Checkout(originalBranch); err != nil {
return errs.NewError(
fmt.Sprintf("Checkout the original branch '%v'", originalBranch), err)
}
// Delete the newly created branch.
deleteErr := deleteBranch()
// In case we haven't pushed anything, we are done.
if !flagPush {
return deleteErr
}
// Delete the branch from the remote repository.
log.Rollback(pushTask)
if _, err := git.Run("push", "--delete", remoteName, branchName); err != nil {
// In case deleteBranch failed, tell the user now
// since we are not going to return that error.
if deleteErr != nil {
errs.Log(deleteErr)
}
return errs.NewError(
fmt.Sprintf("Delete branch '%v' from remote '%v'", branchName, remoteName), err)
}
// Return deleteErr to make sure it propagates up.
return deleteErr
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:101,代码来源:command.go
示例18: runMain
func runMain() (err error) {
tracker, err := modules.GetIssueTracker()
if err != nil {
return err
}
// Fetch stories from the issue tracker.
task := "Fetch stories from the issue tracker"
log.Run(task)
stories, err := tracker.StartableStories()
if err != nil {
return errs.NewError(task, err)
}
if len(stories) == 0 {
return errs.NewError(task, errors.New("no startable stories found"))
}
// Filter out the stories that are not relevant,
// i.e. not owned by the current user or assigned to someone else.
task = "Fetch the current user record from the issue tracker"
user, err := tracker.CurrentUser()
if err != nil {
return errs.NewError(task, err)
}
var filteredStories []common.Story
StoryLoop:
for _, story := range stories {
assignees := story.Assignees()
// Include the story in case there is no assignee set yet.
if len(assignees) == 0 {
filteredStories = append(filteredStories, story)
continue StoryLoop
}
// Include the story in case the current user is assigned.
for _, assignee := range assignees {
if assignee.Id() == user.Id() {
filteredStories = append(filteredStories, story)
continue StoryLoop
}
}
}
stories = filteredStories
// Prompt the user to select a story.
story, err := dialog(
"\nYou can start working on one of the following stories:", stories)
if err != nil {
switch err {
case prompt.ErrNoStories:
return errors.New("no startable stories found")
case prompt.ErrCanceled:
prompt.PanicCancel()
default:
return err
}
}
fmt.Println()
// Create the story branch, optionally.
if flagNoBranch {
log.Log("Not creating any feature branch")
} else {
var act action.Action
act, err = createBranch()
if err != nil {
return err
}
// Roll back on error.
defer action.RollbackTaskOnError(&err, task, act)
}
// Add the current user to the list of story assignees.
task = "Amend the list of story assignees"
log.Run(task)
originalAssignees := story.Assignees()
if err := story.AddAssignee(user); err != nil {
return errs.NewError(task, err)
}
defer action.RollbackTaskOnError(&err, task, action.ActionFunc(func() error {
task := "Reset the list of story assignees"
if err := story.SetAssignees(originalAssignees); err != nil {
return errs.NewError(task, err)
}
return nil
}))
// Start the selected story. No need to roll back.
task = "Start the selected story"
log.Run(task)
return errs.Wrap(task, story.Start())
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:92,代码来源:command.go
示例19: merge
func merge(mergeTask, current, parent string) (act action.Action, err error) {
// Remember the current branch hash.
currentSHA, err := git.BranchHexsha(current)
if err != nil {
return nil, err
}
// Checkout the parent branch so that we can perform the merge.
if err := git.Checkout(parent); err != nil {
return nil, err
}
// Checkout the current branch on return to be consistent.
defer func() {
if ex := git.Checkout(current); ex != nil {
if err == nil {
err = ex
} else {
errs.Log(ex)
}
}
}()
// Perform the merge.
// Use --no-ff in case -merge_no_ff is set.
if flagMergeNoFF {
err = git.Merge(current, "--no-ff")
} else {
err = git.Merge(current)
}
if err != nil {
return nil, err
}
// Return a rollback action.
return action.ActionFunc(func() (err error) {
log.Rollback(mergeTask)
task := fmt.Sprintf("Reset branch '%v' to the original position", current)
// Get the branch is the current branch now.
currentNow, err := gitutil.CurrentBranch()
if err != nil {
return errs.NewError(task, err)
}
// Checkout current in case it is not the same as the current branch now.
if currentNow != current {
if err := git.Checkout(current); err != nil {
return errs.NewError(task, err)
}
defer func() {
if ex := git.Checkout(currentNow); ex != nil {
if err == nil {
err = ex
} else {
errs.Log(ex)
}
}
}()
}
// Reset the branch to the original position.
if err := git.Reset("--keep", currentSHA); err != nil {
return errs.NewError(task, err)
}
return nil
}), nil
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:67,代码来源:mode_parent.go
示例20: postBranch
//.........这里部分代码省略.........
log.Run(task)
if err = git.EnsureBranchSynchronized(currentBranch, remoteName); err != nil {
return errs.NewError(task, err)
}
// Get the commits to be posted
task = "Get the commits to be posted for code review"
commits, err := git.ShowCommitRange(parentBranch + "..")
if err != nil {
return errs.NewError(task, err)
}
// Make sure there are no merge commits.
if err := ensureNoMergeCommits(commits); err != nil {
return err
}
// Prompt the user to confirm.
if err := promptUserToConfirmCommits(commits); err != nil {
return err
}
// Rebase the current branch on top the parent branch.
if !flagNoRebase {
commits, err = rebase(currentBranch, parentBranch)
if err != nil {
return err
}
}
// Ensure the Story-Id tag is there.
commits, _, err = ensureStoryId(commits)
if err != nil {
return err
}
// Get data on the current branch.
task = fmt.Sprintf("Get data on branch '%v'", currentBranch)
remoteCurrentExists, err := git.RemoteBranchExists(currentBranch, remoteName)
if err != nil {
return errs.NewError(task, err)
}
currentUpToDate, err := git.IsBranchSynchronized(currentBranch, remoteName)
if err != nil {
return errs.NewError(task, err)
}
// Merge the current branch into the parent branch unless -no_merge.
pushTask := "Push the current branch"
if flagNoMerge {
// In case the user doesn't want to merge,
// we need to push the current branch.
if !remoteCurrentExists || !currentUpToDate {
if err := push(remoteName, currentBranch); err != nil {
return errs.NewError(pushTask, err)
}
}
} else {
// Still push the current branch if necessary.
if remoteCurrentExists && !currentUpToDate {
if err := push(remoteName, currentBranch); err != nil {
return errs.NewError(pushTask, err)
}
}
// Merge the branch into the parent branch
mergeTask := fmt.Sprintf("Merge branch '%v' into branch '%v'", currentBranch, parentBranch)
log.Run(mergeTask)
act, err := merge(mergeTask, currentBranch, parentBranch)
if err != nil {
return err
}
// Push the parent branch.
if err := push(remoteName, parentBranch); err != nil {
// In case the push fails, we revert the merge as well.
if err := act.Rollback(); err != nil {
errs.Log(err)
}
return errs.NewError(mergeTask, err)
}
// Register a rollback function that just says that
// a pushed merge cannot be reverted.
defer action.RollbackOnError(&err, action.ActionFunc(func() error {
log.Rollback(mergeTask)
hint := "\nCannot revert merge that has already been pushed.\n"
return errs.NewErrorWithHint(
"Revert the merge", errors.New("merge commit already pushed"), hint)
}))
}
// Post the review requests.
if err := postCommitsForReview(commits); err != nil {
return err
}
// In case there is no error, tell the user they can do next.
return printFollowup()
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:101,代码来源:mode_parent.go
注:本文中的github.com/salsaflow/salsaflow/action.ActionFunc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论