本文整理汇总了Golang中github.com/salsaflow/salsaflow/action.ActionFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang ActionFunc函数的具体用法?Golang ActionFunc怎么用?Golang ActionFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ActionFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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.
//.........这里部分代码省略.........