<commit_before>/* walter: a deployment pipeline template
 * Copyright (C) 2014 Recruit Technologies Co., Ltd. and contributors
 * (see CONTRIBUTORS.md)
 *
 * 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 pipelines defines the pipeline and the resources.
package pipelines

import (
	"container/list"
	"fmt"

	"github.com/recruit-tech/walter/messengers"
	"github.com/recruit-tech/walter/services"
	"github.com/recruit-tech/walter/stages"
)

// Pipeline stores the list of stages.
type Pipeline struct {
	Stages list.List
}

// Resources stores the settings loaded from the configuation file.
type Resources struct {
	// Pipeline stores the list of stages to be executed.
	Pipeline *Pipeline

	// Cleanup stores the list of stages extecuted after Pipeline.
	Cleanup *Pipeline

	// Reporter stores the messenger client which report the result to the server.
	Reporter messengers.Messenger

	// RepoService is a client of VCS services such as GitHub and reports the result to the service.
	RepoService services.Service
}

// ReportStageResult throw the results of specified stage to the messenger services.
func (self *Resources) ReportStageResult(stage stages.Stage, resultStr string) {
	name := stage.GetStageName()
	if !self.Reporter.Suppress("result") {
		if resultStr == "true" {
			self.Reporter.Post(
				fmt.Sprintf("[%s][RESULT] Succeeded", name))
		} else if resultStr == "skipped" {
			self.Reporter.Post(
				fmt.Sprintf("[%s][RESULT] Skipped", name))
		} else {
			self.Reporter.Post(
				fmt.Sprintf("[%s][RESULT] Failed", name))
		}
	}

	if stage.GetStageOpts().ReportingFullOutput {
		if out := stage.GetOutResult(); (len(out) > 0) && (!self.Reporter.Suppress("stdout")) {
			self.Reporter.Post(
				fmt.Sprintf("[%s][STDOUT] %s", name, stage.GetOutResult()))
		}
		if err := stage.GetErrResult(); len(err) > 0 && (!self.Reporter.Suppress("stderr")) {
			self.Reporter.Post(
				fmt.Sprintf("[%s][STDERR] %s", name, stage.GetErrResult()))
		}
	}
}

// AddStage appends specified stage to the pipeline.
func (self *Pipeline) AddStage(stage stages.Stage) {
	self.Stages.PushBack(stage)
}

// Size returns the number of stages in the pipeline.
func (self *Pipeline) Size() int {
	return self.Stages.Len()
}

func (self *Pipeline) Build() {
	self.buildDeps(&self.Stages)
}

func (self *Pipeline) buildDeps(stages *list.List) {
}

func NewPipeline() *Pipeline {
	return &Pipeline{}
}<commit_msg>golint changes pipeline.go<commit_after>/* walter: a deployment pipeline template
 * Copyright (C) 2014 Recruit Technologies Co., Ltd. and contributors
 * (see CONTRIBUTORS.md)
 *
 * 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 pipelines defines the pipeline and the resources.
package pipelines

import (
	"container/list"
	"fmt"

	"github.com/recruit-tech/walter/messengers"
	"github.com/recruit-tech/walter/services"
	"github.com/recruit-tech/walter/stages"
)

// Pipeline stores the list of stages.
type Pipeline struct {
	Stages list.List
}

// Resources stores the settings loaded from the configuation file.
type Resources struct {
	// Pipeline stores the list of stages to be executed.
	Pipeline *Pipeline

	// Cleanup stores the list of stages extecuted after Pipeline.
	Cleanup *Pipeline

	// Reporter stores the messenger client which report the result to the server.
	Reporter messengers.Messenger

	// RepoService is a client of VCS services such as GitHub and reports the result to the service.
	RepoService services.Service
}

// ReportStageResult throw the results of specified stage to the messenger services.
func (resources *Resources) ReportStageResult(stage stages.Stage, resultStr string) {
	name := stage.GetStageName()
	if !resources.Reporter.Suppress("result") {
		if resultStr == "true" {
			resources.Reporter.Post(
				fmt.Sprintf("[%s][RESULT] Succeeded", name))
		} else if resultStr == "skipped" {
			resources.Reporter.Post(
				fmt.Sprintf("[%s][RESULT] Skipped", name))
		} else {
			resources.Reporter.Post(
				fmt.Sprintf("[%s][RESULT] Failed", name))
		}
	}

	if stage.GetStageOpts().ReportingFullOutput {
		if out := stage.GetOutResult(); (len(out) > 0) && (!resources.Reporter.Suppress("stdout")) {
			resources.Reporter.Post(
				fmt.Sprintf("[%s][STDOUT] %s", name, stage.GetOutResult()))
		}
		if err := stage.GetErrResult(); len(err) > 0 && (!resources.Reporter.Suppress("stderr")) {
			resources.Reporter.Post(
				fmt.Sprintf("[%s][STDERR] %s", name, stage.GetErrResult()))
		}
	}
}

// AddStage appends specified stage to the pipeline.
func (resources *Pipeline) AddStage(stage stages.Stage) {
	resources.Stages.PushBack(stage)
}

// Size returns the number of stages in the pipeline.
func (resources *Pipeline) Size() int {
	return resources.Stages.Len()
}

//Build builds a pipeline for the current resources
func (resources *Pipeline) Build() {
	resources.buildDeps(&resources.Stages)
}

func (resources *Pipeline) buildDeps(stages *list.List) {
}

//NewPipeline create a new pipeline instance
func NewPipeline() *Pipeline {
	return &Pipeline{}
}
{'fraction_non_alphanumeric': 0.11582435791217896, 'fraction_numerical': 0.0033140016570008283, 'mean_word_length': 4.185567010309279, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '730844', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1777, 'n_words': 614}