diff --git a/cmd/changelog.go b/cmd/changelog.go index 09599c8..e7b7fe9 100644 --- a/cmd/changelog.go +++ b/cmd/changelog.go @@ -20,6 +20,8 @@ import ( "os/exec" "github.com/gaocegege/maintainer/config" + "github.com/gaocegege/maintainer/dep" + "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -58,6 +60,15 @@ func init() { } func changelogRun() error { + isInstalled, err := dep.ChangelogGenerator.IsInstalled() + if err != nil { + return err + } + if isInstalled != true { + if err = dep.ChangelogGenerator.Install(); err != nil { + return err + } + } token := viper.GetString(config.Token) // Override token in CLI. if *tokenValue != "" { @@ -68,7 +79,7 @@ func changelogRun() error { // Set STDERR and STDOUT to STDOUT of maintainer. cmd.Stderr = os.Stdout cmd.Stdout = os.Stdout - if err := cmd.Run(); err != nil { + if err = cmd.Run(); err != nil { return err } return nil diff --git a/dep/changelog.go b/dep/changelog.go new file mode 100644 index 0000000..91dbe5e --- /dev/null +++ b/dep/changelog.go @@ -0,0 +1,50 @@ +// Copyright © 2017 Maintainer Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dep + +import "errors" + +const ( + nameGitHubChangelogGenerator string = "github_changelog_generator" +) + +// GitHubChangelogGenerator is the type for github_changelog_generator. +// See https://github.com/skywinder/Github-Changelog-Generator. +type GitHubChangelogGenerator struct { + Dependency + isInstalled bool +} + +// NewGitHubChangelogGenerator returns a new GitHubChangelogGenerator instance. +func NewGitHubChangelogGenerator() *GitHubChangelogGenerator { + return &GitHubChangelogGenerator{ + isInstalled: false, + } +} + +// Name implements Dependency.Name(). +func (g *GitHubChangelogGenerator) Name() string { + return nameGitHubChangelogGenerator +} + +// IsInstalled implements Dependency.IsInstalled(). +func (g *GitHubChangelogGenerator) IsInstalled() (bool, error) { + return false, errors.New("Not Implemented") +} + +// Install implements Dependency.Install(). +func (g *GitHubChangelogGenerator) Install() error { + return errors.New("Not Implemented") +} diff --git a/dep/dependency.go b/dep/dependency.go new file mode 100644 index 0000000..3947e0e --- /dev/null +++ b/dep/dependency.go @@ -0,0 +1,25 @@ +// Copyright © 2017 Maintainer Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dep + +// Dependency is the type for the dependency. +type Dependency interface { + // IsInstalled check where the dependency is installed. + IsInstalled() (bool, error) + // Install installs the specific dependency and returns error if fails. + Install() error + // Name return the name of the dependency. + Name() string +} diff --git a/dep/init.go b/dep/init.go new file mode 100644 index 0000000..261353e --- /dev/null +++ b/dep/init.go @@ -0,0 +1,20 @@ +// Copyright © 2017 Maintainer Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dep + +var ( + // ChangelogGenerator is the instance for ChangelogGenerator. + ChangelogGenerator = NewGitHubChangelogGenerator() +)