Beispiel #1
0
func InitOrDie() {
	if err := Init(false); err != nil {
		if errs.RootCause(err) != repo.ErrInitialised {
			errs.Fatal(err)
		}
	}
}
Beispiel #2
0
func run(cmd *gocli.Command, args []string) {
	if len(args) != 0 {
		cmd.Usage()
		os.Exit(2)
	}

	if err := app.Init(flagForce); err != nil {
		if errs.RootCause(err) == repo.ErrInitialised {
			log.Log("The repository has been already initialised")
			return
		}
		errs.Fatal(err)
	}
}
Beispiel #3
0
func tryToStageRunningRelease() {
	stagingTask := "Try to stage the next release for acceptance"
	log.Run(stagingTask)
	_, err := commands.Stage(&commands.StageOptions{
		SkipFetch: true,
	})
	if err != nil {
		// Not terribly pretty, but it works. We just handle the known errors and continue.
		// It is ok when the release branch does not exist yet or the release cannot be staged
		// in the issue tracker.
		rootCause := errs.RootCause(err)
		if ex, ok := rootCause.(*git.ErrRefNotFound); ok {
			log.Log(fmt.Sprintf("Git reference '%v' not found, not staging any release", ex.Ref))
		} else if rootCause == common.ErrNotStageable {
			log.Log("The next release cannot be staged yet, staging canceled")
		} else {
			errs.LogError(stagingTask, err)
			log.Log("Failed to stage the next release, continuing anyway ...")
		}
	}
}
Beispiel #4
0
// RunModuleBootstrapDialog runs the module bootstrapping dialog for every
// section specification passed into the function.
func RunModuleBootstrapDialog(sections ...*ModuleDialogSection) error {
	// Try to read the local configuration file.
	localConfig, err := config.ReadLocalConfig()
	if err != nil {
		if !os.IsNotExist(errs.RootCause(err)) {
			return err
		}
	}

	for _, section := range sections {
		modules := section.AvailableModules

		// In case there are no modules available, skip the section.
		if len(modules) == 0 {
			continue
		}

		// Find the module for the given module kind.
		// Either use the one that is already configured
		// or prompt the user to select one.
		module := tryToFindActiveModule(localConfig, modules)
		if module == nil {
			var err error
			module, err = promptUserToSelectModule(section.AvailableModules, section.Optional)
			if err != nil {
				return err
			}
		}

		// Run the configuration dialog for the selected module.
		// The module can be unset in case it is optional.
		if module != nil {
			if err := BootstrapConfig(module.ConfigSpec()); err != nil {
				return err
			}
		}
	}

	return nil
}
Beispiel #5
0
func load(args *loadArgs) error {
	// Save the args into regular variables.
	var (
		configKind     = args.configKind
		configKey      = args.configKey
		container      = args.configContainer
		readConfig     = args.readConfig
		emptyConfig    = args.emptyConfig
		disallowPrompt = args.disallowPrompt
	)

	// Do nothing in case the container is nil.
	if container == nil {
		return nil
	}

	// Read the configuration file.
	configFile, err := readConfig()
	if err != nil {
		if emptyConfig == nil || !os.IsNotExist(errs.RootCause(err)) {
			return err
		}
		// In case the file is not there, initialise a new one.
		configFile = emptyConfig()
	}

	prompt := func(err error) error {
		if disallowPrompt {
			dialogTask := "Prompt the user for configuration according to the spec"
			dialogErr := errors.New("configuration dialog is disabled")
			dialogHint := `
The configuration dialog for the local configuration file can only be run
during 'repo bootstrap' so that the configuration file is not modified
without anybody noticing in the middle of other work being done.

Please fix the issues manually, either by manually editing the local
configuration file or by re-running 'repo bootstrap' command.

Don't forget to commit the changes.

`
			if ex, ok := err.(errs.Err); ok {
				err := errs.NewErrorWithHint(dialogTask, dialogErr, dialogHint)
				return errs.NewErrorWithHint(ex.Task(), err, ex.Hint())
			}
			return errs.NewErrorWithHint(dialogTask, err, dialogHint)
		}
		return promptAndWrite(configFile, args)
	}

	// Find the config record for the given key.
	// In case there is an error and the prompt is allowed, prompt the user.
	section, err := configFile.ConfigRecord(configKey)
	if err != nil {
		return prompt(err)
	}

	// Unmarshal the record according to the spec.
	// In case there is an error and the prompt is allowed, prompt the user.
	if err := unmarshal(section.RawConfig, container); err != nil {
		fmt.Println()
		log.Log(fmt.Sprintf(
			"Failed to unmarshal %v configuration, will try to run the bootstrap dialog",
			configKind))
		log.NewLine(fmt.Sprintf("(err = %v)", err.Error()))
		return prompt(err)
	}

	// Validate the returned object according to the spec.
	// In case there is an error and the prompt is allowed, prompt the user.
	if err := validate(container, section.Path()); err != nil {
		fmt.Println()
		log.Log(fmt.Sprintf(
			"%v configuration section invalid, will try to run the bootstrap dialog",
			strings.Title(configKind)))
		log.NewLine(fmt.Sprintf("(error = %v)", err.Error()))
		return prompt(err)
	}

	return nil
}