Beispiel #1
0
func repoCreate(c *cobra.Command, args []string) {
	if len(args) < 1 {
		Fail(1, "Valid arguments: <id> [<clone repo url>]\n")
	}

	id, err := NewGenericLocator(git.ResourceTypeRepository, args[0])
	if err != nil {
		Fail(1, "You must pass one valid repository name: %s\n", err.Error())
	}

	if id.ResourceType() != git.ResourceTypeRepository {
		Fail(1, "You must pass one valid repository name: %s\n", err.Error())
	}

	Executor{
		On: Locators{id},
		Serial: func(on Locator) jobs.Job {
			var req http.HttpCreateRepositoryRequest
			req = http.HttpCreateRepositoryRequest{}
			req.Id = git.RepoIdentifier(on.(ResourceLocator).Identifier())

			return &req
		},
		Output:    os.Stdout,
		LocalInit: LocalInitializers(systemd.Start, containers.InitializeData),
	}.StreamAndExit()
}
Beispiel #2
0
func (e *Command) repoCreate(c *cobra.Command, args []string) {
	if len(args) < 1 {
		Fail(1, "Valid arguments: <id> [<clone repo url>]\n")
	}

	t := e.Transport.Get()

	id, err := NewResourceLocator(t, git.ResourceTypeRepository, args[0])
	if err != nil {
		Fail(1, "You must pass one valid repository name: %s\n", err.Error())
	}
	if id.(*ResourceLocator).Type != git.ResourceTypeRepository {
		Fail(1, "You must pass one valid repository name: %s\n", err.Error())
	}

	cloneUrl := ""
	if len(args) == 2 {
		cloneUrl = args[1]
	}

	Executor{
		On: Locators{id},
		Serial: func(on Locator) JobRequest {
			return &gitjobs.CreateRepositoryRequest{
				Id:        git.RepoIdentifier(on.(*ResourceLocator).Id),
				CloneUrl:  cloneUrl,
				RequestId: jobs.NewRequestIdentifier(),
			}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
Beispiel #3
0
func repoCreate(c *cobra.Command, args []string) {
	if len(args) < 1 {
		Fail(1, "Valid arguments: <id> [<clone repo url>]\n")
	}

	t := c.Flags().Lookup("transport").Value.(*transport.TransportFlag).Get()

	id, err := NewResourceLocator(t, git.ResourceTypeRepository, args[0])
	if err != nil {
		Fail(1, "You must pass one valid repository name: %s\n", err.Error())
	}
	if id.(*ResourceLocator).Type != git.ResourceTypeRepository {
		Fail(1, "You must pass one valid repository name: %s\n", err.Error())
	}

	cloneUrl := ""
	if len(args) == 2 {
		cloneUrl = args[1]
	}

	Executor{
		On: Locators{id},
		Serial: func(on Locator) jobs.Job {
			return &gitjobs.CreateRepositoryRequest{
				Id:        git.RepoIdentifier(on.(*ResourceLocator).Id),
				CloneUrl:  cloneUrl,
				RequestId: jobs.NewRequestIdentifier(),
			}
		},
		Output:    os.Stdout,
		LocalInit: LocalInitializers(systemd.Start, containers.InitializeData),
		Transport: t,
	}.StreamAndExit()
}
Beispiel #4
0
func HandleCreateRepositoryRequest(conf *http.HttpConfiguration, context *http.HttpContext, r *rest.Request) (interface{}, error) {
	repositoryId, errg := containers.NewIdentifier(r.PathParam("id"))
	if errg != nil {
		return nil, errg
	}
	// TODO: convert token into a safe clone spec and commit hash
	return &gitjobs.CreateRepositoryRequest{
		git.RepoIdentifier(repositoryId),
		r.URL.Query().Get("source"),
		context.Id,
	}, nil
}
Beispiel #5
0
func HandleGitArchiveContentRequest(conf *http.HttpConfiguration, context *http.HttpContext, r *rest.Request) (interface{}, error) {
	repoId, errr := containers.NewIdentifier(r.PathParam("id"))
	if errr != nil {
		return nil, jobs.SimpleError{jobs.ResponseInvalidRequest, fmt.Sprintf("Invalid repository identifier: %s", errr.Error())}
	}
	ref, errc := gitjobs.NewGitCommitRef(r.PathParam("ref"))
	if errc != nil {
		return nil, jobs.SimpleError{jobs.ResponseInvalidRequest, fmt.Sprintf("Invalid commit ref: %s", errc.Error())}
	}

	return &gitjobs.GitArchiveContentRequest{
		git.RepoIdentifier(repoId),
		ref,
	}, nil
}
Beispiel #6
0
func initRepository(cmd *cobra.Command, args []string) {
	if len(args) < 1 || len(args) > 2 {
		Fail(1, "Valid arguments: <repo_id> [<repo_url>]\n")
	}

	repoId, err := containers.NewIdentifier(args[0])
	if err != nil {
		Fail(1, "Argument 1 must be a valid repository identifier: %s\n", err.Error())
	}

	repoUrl := ""
	if len(args) == 2 {
		repoUrl = args[1]
	}

	if err := gitjobs.InitializeRepository(git.RepoIdentifier(repoId), repoUrl); err != nil {
		Fail(2, "Unable to initialize repository %s\n", err.Error())
	}
}