Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Check and install dependencies #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions dep/changelog.go
Original file line number Diff line number Diff line change
@@ -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")
}
25 changes: 25 additions & 0 deletions dep/dependency.go
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 20 additions & 0 deletions dep/init.go
Original file line number Diff line number Diff line change
@@ -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()
)