本文整理汇总了Golang中github.com/salsaflow/salsaflow/log.Run函数的典型用法代码示例。如果您正苦于以下问题:Golang Run函数的具体用法?Golang Run怎么用?Golang Run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Run函数的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: 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
}
示例3: fetchOrUpdateSkeleton
func fetchOrUpdateSkeleton(skeleton string) error {
// Parse the skeleton string.
parts := strings.SplitN(skeleton, "/", 2)
if len(parts) != 2 {
return fmt.Errorf("not a valid repository path string: %v", skeleton)
}
owner, repo := parts[0], parts[1]
// Create the cache directory if necessary.
task := "Make sure the local cache directory exists"
cacheDir, err := cacheDirectoryAbsolutePath()
if err != nil {
return errs.NewError(task, err)
}
if err := os.MkdirAll(cacheDir, 0755); err != nil {
return errs.NewError(task, err)
}
// Pull or close the given skeleton.
task = "Pull or clone the given skeleton"
skeletonDir := filepath.Join(cacheDir, "github.com", owner)
if err := os.MkdirAll(skeletonDir, 0755); err != nil {
return errs.NewError(task, err)
}
skeletonPath := filepath.Join(skeletonDir, repo)
if _, err := os.Stat(skeletonPath); err != nil {
if !os.IsNotExist(err) {
return errs.NewError(task, err)
}
// The directory does not exist, hence we clone.
task := fmt.Sprintf("Clone skeleton '%v'", skeleton)
log.Run(task)
args := []string{
"clone",
"--single-branch",
fmt.Sprintf("https://github.com/%v/%v", owner, repo),
skeletonPath,
}
if _, err := git.Run(args...); err != nil {
return errs.NewError(task, err)
}
return nil
}
// The skeleton directory exists, hence we pull.
task = fmt.Sprintf("Pull skeleton '%v'", skeleton)
log.Run(task)
cmd, _, stderr := shell.Command("git", "pull")
cmd.Dir = skeletonPath
if err := cmd.Run(); err != nil {
return errs.NewErrorWithHint(task, err, stderr.String())
}
return nil
}
示例4: linkCommitsToReviewIssue
func linkCommitsToReviewIssue(
config *moduleConfig,
owner string,
repo string,
issueNum int,
commits []*git.Commit,
) {
// Instantiate an API client.
client := ghutil.NewClient(config.Token)
// Loop over the commits and post a commit comment for each of them.
for _, commit := range commits {
task := fmt.Sprintf("Link commit %v to the associated review issue", commit.SHA)
log.Run(task)
body := fmt.Sprintf(
"This commit is being reviewed as a part of review issue #%v.", issueNum)
comment := &github.RepositoryComment{
Body: &body,
}
_, _, err := client.Repositories.CreateComment(owner, repo, commit.SHA, comment)
if err != nil {
// Just print the error to the console.
errs.LogError(task, err)
}
}
}
示例5: 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
}
示例6: postAssignedReviewRequest
// postAssignedReviewRequest can be used to post
// the commits associated with the given story for review.
func postAssignedReviewRequest(
config *moduleConfig,
owner string,
repo string,
story common.Story,
commits []*git.Commit,
opts map[string]interface{},
) (*github.Issue, []*git.Commit, error) {
// Search for an existing review issue for the given story.
task := fmt.Sprintf("Search for an existing review issue for story %v", story.ReadableId())
log.Run(task)
client := ghutil.NewClient(config.Token)
issue, err := ghissues.FindReviewIssueForStory(client, owner, repo, story.ReadableId())
if err != nil {
return nil, nil, errs.NewError(task, err)
}
// Decide what to do next based on the search results.
if issue == nil {
// No review issue found for the given story, create a new issue.
issue, err := createAssignedReviewRequest(config, owner, repo, story, commits, opts)
if err != nil {
return nil, nil, err
}
return issue, commits, nil
}
// An existing review issue found, extend it.
return extendReviewRequest(config, owner, repo, issue, commits, opts)
}
示例7: Release
func (release *runningRelease) Release() error {
task := "Ping Sprintly to register the deployment"
log.Run(task)
// Create the Sprintly deployment.
return release.deploy(release.config.ProductionEnvironment())
}
示例8: EnsureStageable
func (release *runningRelease) EnsureStageable() error {
task := "Make sure the stories can be staged"
log.Run(task)
// Load the assigned stories.
stories, err := release.loadStories()
if err != nil {
return errs.NewError(task, err)
}
var details bytes.Buffer
tw := tabwriter.NewWriter(&details, 0, 8, 4, '\t', 0)
io.WriteString(tw, "\n")
io.WriteString(tw, "Story URL\tError\n")
io.WriteString(tw, "=========\t=====\n")
// For a story to be stageable, it must be in the Finished stage.
// That by definition means that it has been reviewed and verified.
for _, story := range stories {
if !stateAtLeast(story, pivotal.StoryStateFinished) {
fmt.Fprintf(tw, "%v\t%v\n", story.URL, "story not finished yet")
err = common.ErrNotStageable
}
}
if err != nil {
io.WriteString(tw, "\n")
tw.Flush()
return errs.NewErrorWithHint(task, err, details.String())
}
return nil
}
示例9: 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
}
示例10: FindMilestoneByTitle
func FindMilestoneByTitle(
client *github.Client,
owner string,
repo string,
title string,
) (*github.Milestone, error) {
// Fetch milestones for the given repository.
task := fmt.Sprintf("Search for GitHub milestone '%v'", title)
log.Run(task)
milestones, _, err := client.Issues.ListMilestones(owner, repo, nil)
if err != nil {
return nil, errs.NewError(task, err)
}
// Find the right one.
for _, milestone := range milestones {
if *milestone.Title == title {
return &milestone, nil
}
}
// Milestone not found.
return nil, nil
}
示例11: 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
}
示例12: 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
}
示例13: EnsureClosable
func (r *release) EnsureClosable() error {
// Prepare for API calls.
_, owner, repo, err := r.prepareForApiCalls()
if err != nil {
return err
}
// Get the relevant review milestone.
releaseString := r.v.BaseString()
task := fmt.Sprintf("Get GitHub review milestone for release %v", releaseString)
log.Run(task)
milestone, err := milestoneForVersion(r.tool.config, owner, repo, r.v)
if err != nil {
return errs.NewError(task, err)
}
if milestone == nil {
return errs.NewErrorWithHint(task, errors.New("milestone not found"),
fmt.Sprintf("\nMake sure the review milestone for release %v exists\n\n", r.v))
}
// 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 {
hint := fmt.Sprintf(
"\nreview milestone for release %v cannot be closed: %v issue(s) open\n\n",
releaseString, num)
return errs.NewErrorWithHint(task, common.ErrNotClosable, hint)
}
r.closingMilestone = milestone
return nil
}
示例14: createIssue
func createIssue(
task string,
config Config,
owner string,
repo string,
issueTitle string,
issueBody string,
milestone *github.Milestone,
) (issue *github.Issue, err error) {
log.Run(task)
client := ghutil.NewClient(config.Token())
labels := []string{config.ReviewLabel()}
issue, _, err = client.Issues.Create(owner, repo, &github.IssueRequest{
Title: github.String(issueTitle),
Body: github.String(issueBody),
Labels: &labels,
Milestone: milestone.Number,
})
if err != nil {
return nil, errs.NewError(task, err)
}
log.Log(fmt.Sprintf("GitHub issue #%v created", *issue.Number))
return issue, nil
}
示例15: 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
}