本文整理汇总了Golang中v/io/jiri/tool.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DisableRemoteManifestPush
// DisableRemoteManifestPush disables pushes to the remote manifest
// repository.
func (root FakeJiriRoot) DisableRemoteManifestPush(ctx *tool.Context) error {
dir := tool.RootDirOpt(filepath.Join(root.remote, manifestProject))
if err := ctx.Git(dir).CheckoutBranch("master"); err != nil {
return err
}
return nil
}
示例2: createRemoteManifest
func createRemoteManifest(t *testing.T, ctx *tool.Context, dir string, remotes []string) {
manifestDir, perm := filepath.Join(dir, "v2"), os.FileMode(0755)
if err := ctx.Run().MkdirAll(manifestDir, perm); err != nil {
t.Fatalf("%v", err)
}
manifest := Manifest{}
for i, remote := range remotes {
project := Project{
Name: remote,
Path: localProjectName(i),
Protocol: "git",
Remote: remote,
}
manifest.Projects = append(manifest.Projects, project)
}
manifest.Hosts = []Host{
Host{
Name: "gerrit",
Location: "git://example.com/gerrit",
},
Host{
Name: "git",
Location: "git://example.com/git",
},
}
commitManifest(t, ctx, &manifest, dir)
}
示例3: getManifest
func getManifest(ctx *tool.Context) string {
manifest := ctx.Manifest()
if manifest != "" {
return manifest
}
return defaultManifest
}
示例4: createOncallFile
func createOncallFile(t *testing.T, ctx *tool.Context) {
content := `<?xml version="1.0" ?>
<rotation>
<shift>
<primary>spetrovic</primary>
<secondary>suharshs</secondary>
<startDate>Nov 5, 2014 12:00:00 PM</startDate>
</shift>
<shift>
<primary>suharshs</primary>
<secondary>jingjin</secondary>
<startDate>Nov 12, 2014 12:00:00 PM</startDate>
</shift>
<shift>
<primary>jsimsa</primary>
<secondary>toddw</secondary>
<startDate>Nov 19, 2014 12:00:00 PM</startDate>
</shift>
</rotation>`
oncallRotationsFile, err := OncallRotationPath(ctx)
if err != nil {
t.Fatalf("%v", err)
}
dir := filepath.Dir(oncallRotationsFile)
dirMode := os.FileMode(0700)
if err := ctx.Run().MkdirAll(dir, dirMode); err != nil {
t.Fatalf("MkdirAll(%q, %v) failed: %v", dir, dirMode, err)
}
fileMode := os.FileMode(0644)
if err := ioutil.WriteFile(oncallRotationsFile, []byte(content), fileMode); err != nil {
t.Fatalf("WriteFile(%q, %q, %v) failed: %v", oncallRotationsFile, content, fileMode, err)
}
}
示例5: getDependencyPathFileName
func getDependencyPathFileName(ctx *tool.Context, branch string) (string, error) {
topLevel, err := ctx.Git().TopLevel()
if err != nil {
return "", err
}
return filepath.Join(topLevel, project.MetadataDirName(), branch, dependencyPathFileName), nil
}
示例6: writeMetadata
// writeMetadata stores the given project metadata in the directory
// identified by the given path.
func writeMetadata(ctx *tool.Context, project Project, dir string) (e error) {
metadataDir := filepath.Join(dir, metadataDirName)
cwd, err := os.Getwd()
if err != nil {
return err
}
defer collect.Error(func() error { return ctx.Run().Chdir(cwd) }, &e)
if err := ctx.Run().MkdirAll(metadataDir, os.FileMode(0755)); err != nil {
return err
}
if err := ctx.Run().Chdir(metadataDir); err != nil {
return err
}
// Replace absolute project paths with relative paths to make it
// possible to move the $JIRI_ROOT directory locally.
relPath, err := ToRel(project.Path)
if err != nil {
return err
}
project.Path = relPath
bytes, err := xml.Marshal(project)
if err != nil {
return fmt.Errorf("Marhsal() failed: %v", err)
}
metadataFile := filepath.Join(metadataDir, metadataFileName)
tmpMetadataFile := metadataFile + ".tmp"
if err := ctx.Run().WriteFile(tmpMetadataFile, bytes, os.FileMode(0644)); err != nil {
return err
}
if err := ctx.Run().Rename(tmpMetadataFile, metadataFile); err != nil {
return err
}
return nil
}
示例7: gitCookies
// gitCookies attempts to read and parse cookies from the .gitcookies file in
// the users home directory.
func gitCookies(ctx *tool.Context) []*http.Cookie {
cookies := []*http.Cookie{}
homeDir := os.Getenv("HOME")
if homeDir == "" {
return cookies
}
cookieFile := filepath.Join(homeDir, ".gitcookies")
bytes, err := ctx.Run().ReadFile(cookieFile)
if err != nil {
return cookies
}
lines := strings.Split(string(bytes), "\n")
for _, line := range lines {
if strings.TrimSpace(line) == "" {
continue
}
cookie, err := parseCookie(line)
if err != nil {
fmt.Fprintf(ctx.Stderr(), "error parsing cookie in .gitcookies: %v\n", err)
} else {
cookies = append(cookies, cookie)
}
}
return cookies
}
示例8: setPathHelper
// setPathHelper is a utility function for setting path environment
// variables for different types of workspaces.
func setPathHelper(ctx *tool.Context, env *envvar.Vars, name, root string, workspaces []string, suffix string) error {
path := env.GetTokens(name, ":")
projects, _, err := project.ReadManifest(ctx)
if err != nil {
return err
}
for _, workspace := range workspaces {
absWorkspace := filepath.Join(root, workspace, suffix)
// Only append an entry to the path if the workspace is rooted
// under a jiri project that exists locally or vice versa.
for _, project := range projects {
// We check if <project.Path> is a prefix of <absWorkspace> to
// account for Go workspaces nested under a single jiri project,
// such as: $JIRI_ROOT/release/projects/chat/go.
//
// We check if <absWorkspace> is a prefix of <project.Path> to
// account for Go workspaces that span multiple jiri projects,
// such as: $JIRI_ROOT/release/go.
if strings.HasPrefix(absWorkspace, project.Path) || strings.HasPrefix(project.Path, absWorkspace) {
if _, err := ctx.Run().Stat(filepath.Join(absWorkspace)); err == nil {
path = append(path, absWorkspace)
break
}
}
}
}
env.SetTokens(name, path, ":")
return nil
}
示例9: loadAliases
func loadAliases(ctx *tool.Context) (*aliasMaps, error) {
aliasesFile := aliasesFlag
if aliasesFile == "" {
dataDir, err := project.DataDirPath(ctx, tool.Name)
if err != nil {
return nil, err
}
aliasesFile = filepath.Join(dataDir, aliasesFileName)
}
bytes, err := ctx.Run().ReadFile(aliasesFile)
if err != nil {
return nil, err
}
var data aliasesSchema
if err := xml.Unmarshal(bytes, &data); err != nil {
return nil, fmt.Errorf("Unmarshal(%v) failed: %v", string(bytes), err)
}
aliases := &aliasMaps{
emails: map[string]string{},
names: map[string]string{},
}
for _, email := range data.Emails {
for _, alias := range email.Aliases {
aliases.emails[alias] = email.Canonical
}
}
for _, name := range data.Names {
for _, alias := range name.Aliases {
aliases.names[alias] = name.Canonical
}
}
return aliases, nil
}
示例10: checkDependents
// checkDependents makes sure that all CLs in the sequence of
// dependent CLs leading to (but not including) the current branch
// have been exported to Gerrit.
func checkDependents(ctx *tool.Context) (e error) {
originalBranch, err := ctx.Git().CurrentBranchName()
if err != nil {
return err
}
branches, err := getDependentCLs(ctx, originalBranch)
if err != nil {
return err
}
for i := 1; i < len(branches); i++ {
file, err := getCommitMessageFileName(ctx, branches[i])
if err != nil {
return err
}
if _, err := ctx.Run().Stat(file); err != nil {
if !os.IsNotExist(err) {
return err
}
return fmt.Errorf(`Failed to export the branch %q to Gerrit because its ancestor %q has not been exported to Gerrit yet.
The following steps are needed before the operation can be retried:
$ git checkout %v
$ jiri cl mail
$ git checkout %v
# retry the original command
`, originalBranch, branches[i], branches[i], originalBranch)
}
}
return nil
}
示例11: assertFilesNotCommitted
// assertFilesNotCommitted asserts that the files exist and are *not*
// committed in the current branch.
func assertFilesNotCommitted(t *testing.T, ctx *tool.Context, files []string) {
assertFilesExist(t, ctx, files)
for _, file := range files {
if ctx.Git().IsFileCommitted(file) {
t.Fatalf("expected file %v not to be committed but it is", file)
}
}
}
示例12: saveConfig
func saveConfig(ctx *tool.Context, config *Config, path string) error {
var data configSchema
data.APICheckProjects = set.String.ToSlice(config.apiCheckProjects)
sort.Strings(data.APICheckProjects)
data.CopyrightCheckProjects = set.String.ToSlice(config.copyrightCheckProjects)
sort.Strings(data.CopyrightCheckProjects)
for _, workspace := range config.goWorkspaces {
data.GoWorkspaces = append(data.GoWorkspaces, workspace)
}
sort.Strings(data.GoWorkspaces)
for _, job := range config.jenkinsMatrixJobs {
data.JenkinsMatrixJobs = append(data.JenkinsMatrixJobs, job)
}
sort.Sort(data.JenkinsMatrixJobs)
for name, tests := range config.projectTests {
data.ProjectTests = append(data.ProjectTests, testGroupSchema{
Name: name,
Tests: tests,
})
}
sort.Sort(data.ProjectTests)
for name, dependencies := range config.testDependencies {
data.TestDependencies = append(data.TestDependencies, dependencyGroupSchema{
Name: name,
Dependencies: dependencies,
})
}
sort.Sort(data.TestDependencies)
for name, tests := range config.testGroups {
data.TestGroups = append(data.TestGroups, testGroupSchema{
Name: name,
Tests: tests,
})
}
sort.Sort(data.TestGroups)
for name, parts := range config.testParts {
data.TestParts = append(data.TestParts, partGroupSchema{
Name: name,
Parts: parts,
})
}
sort.Sort(data.TestParts)
for _, workspace := range config.vdlWorkspaces {
data.VDLWorkspaces = append(data.VDLWorkspaces, workspace)
}
sort.Strings(data.VDLWorkspaces)
bytes, err := xml.MarshalIndent(data, "", " ")
if err != nil {
return fmt.Errorf("MarshalIndent(%v) failed: %v", data, err)
}
if err := ctx.Run().MkdirAll(filepath.Dir(path), os.FileMode(0755)); err != nil {
return err
}
if err := ctx.Run().WriteFile(path, bytes, os.FileMode(0644)); err != nil {
return err
}
return nil
}
示例13: assertFilesDoNotExist
// assertFilesDoNotExist asserts that the files do not exist.
func assertFilesDoNotExist(t *testing.T, ctx *tool.Context, files []string) {
for _, file := range files {
if _, err := ctx.Run().Stat(file); err != nil && !os.IsNotExist(err) {
t.Fatalf("%v", err)
} else if err == nil {
t.Fatalf("expected file %v to not exist but it did", file)
}
}
}
示例14: Test
func (op deleteOperation) Test(ctx *tool.Context) error {
if _, err := ctx.Run().Stat(op.source); err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("cannot delete %q as it does not exist", op.source)
}
return err
}
return nil
}
示例15: assertCommitCount
// assertCommitCount asserts that the commit count between two
// branches matches the expectedCount.
func assertCommitCount(t *testing.T, ctx *tool.Context, branch, baseBranch string, expectedCount int) {
got, err := ctx.Git().CountCommits(branch, baseBranch)
if err != nil {
t.Fatalf("%v", err)
}
if want := 1; got != want {
t.Fatalf("unexpected number of commits: got %v, want %v", got, want)
}
}