Ejemplo n.º 1
0
// Handle branches message
func (plugin *branches) Handle(req *comm.Request) (err error) {
	t := comm.Mention(req.User)

	if len(plugin.config.Branches) == 0 {
		t += "no known branches"
	} else {
		t += "known branches - "
		for k, v := range plugin.config.Branches {
			if k > 0 {
				t += ", "
			}
			t += comm.BuildwebBranchURL(v)
		}
	}

	iop := &comm.Interop{
		Request: req,
		Response: &comm.Response{
			Channel:    req.Channel,
			Text:       t,
			Parameters: comm.DefaultMessageParameters()}}
	comm.SB.ChanResponse <- iop.Response
	comm.SB.ChanPersist <- iop

	return
}
Ejemplo n.º 2
0
// Handle targets message
func (plugin *targets) Handle(req *comm.Request) error {
	t := comm.Mention(req.User)

	if len(plugin.config.Targets) < 1 {
		t += "no known targets"
	} else {
		t += "known targets - "
		for k, v := range plugin.config.Targets {
			if k > 0 {
				t += ", "
			}
			t += comm.BuildwebTargetURL(v)
		}
	}

	iop := &comm.Interop{
		Request: req,
		Response: &comm.Response{
			Channel:    req.Channel,
			Text:       t,
			Parameters: comm.DefaultMessageParameters()}}
	comm.SB.ChanResponse <- iop.Response
	comm.SB.ChanPersist <- iop

	return nil
}
Ejemplo n.º 3
0
// Handle testrun message
// CAT URL:
// http://cat.eng.vmware.com/api/v2.0/testrun/?format=json&limit=1&order_by=-endtime&deliverables__build__branch=main&area__name=SingleVA_PostCheckin&result=PASS
func (plugin *testrun) Handle(req *comm.Request) error {
	url := plugin.config.URLs.BaseCatURL + plugin.config.URLs.BaseTestrunURL

	params := DefaultCatParams()

	params["deliverables__build__branch"] = defaultBranch
	if len(req.Arguments) > 2 {
		params["deliverables__build__branch"] = req.Arguments[2]
	}

	params["area__name"] = defaultArea
	if len(req.Arguments) > 3 {
		params["area__name"] = req.Arguments[3]
	}

	if len(req.Arguments) > 4 {
		params["result"] = req.Arguments[4]
	}

	p := params.AsUrlValues()
	s := napping.Session{}
	j := TestrunJSON{}
	r, err := s.Get(url, &p, &j, nil)
	if err != nil {
		return err
	}
	if r.Status() != 200 {
		return fmt.Errorf("expect response status code 200. Actual %d %s", r.Status(), params)
	}
	if len(j.Objects) == 0 {
		return fmt.Errorf("testrun %s/%s not found", params["deliverables__build__branch"], params["area__name"])
	}
	if len(j.Objects) != 1 {
		return fmt.Errorf("expected one object. Actual %d %s", len(j.Objects), params)
	}

	t := comm.Mention(req.User)
	t += fmt.Sprintf("testrun for %s ",
		comm.CatTestrunURL(j.Objects[0].ID,
			fmt.Sprintf("%s/%s", params["deliverables__build__branch"], params["area__name"])))
	t += fmt.Sprintf("is *%s* ", j.Objects[0].Result)
	t += fmt.Sprintf("(%s)", comm.CatTestrunResultsURL(j.Objects[0].ResultsDir))

	iop := &comm.Interop{
		Request: req,
		Response: &comm.Response{
			Channel:    req.Channel,
			Text:       t,
			Parameters: comm.DefaultMessageParameters()}}
	comm.SB.ChanResponse <- iop.Response
	comm.SB.ChanPersist <- iop

	return nil
}
Ejemplo n.º 4
0
// HandleUnknown handles unknown directives
func (pm *PluginManager) HandleUnknown(req *comm.Request) error {
	text := comm.Mention(req.User)
	text += fmt.Sprintf("unknown request - *%s*", strings.Join(req.Arguments, " "))

	comm.SB.ChanResponse <- &comm.Response{
		Channel:    req.Channel,
		Text:       text,
		Parameters: comm.DefaultMessageParameters()}

	return nil
}
Ejemplo n.º 5
0
// HandleError handles plugin handle error
func (pm *PluginManager) HandleError(req *comm.Request, err error) error {
	text := comm.Mention(req.User)
	text += fmt.Sprintf("error occurred - *%s*", err)

	comm.SB.ChanResponse <- &comm.Response{
		Channel:    req.Channel,
		Text:       text,
		Parameters: comm.DefaultMessageParameters()}

	return nil
}
Ejemplo n.º 6
0
// Handle build message
// CAT URL:
// http://cat.eng.vmware.com/api/v2.0/deliverable/?format=json&limit=1&order_by=-endtime&build__branch=<1>&targets=<2>&result=<3>
func (plugin *build) Handle(req *comm.Request) error {
	url := plugin.config.URLs.BaseCatURL + plugin.config.URLs.BaseBuildURL

	params := DefaultCatParams()

	params["build__branch"] = defaultBranch
	if len(req.Arguments) > 2 {
		params["build__branch"] = req.Arguments[2]
	}

	params["targets"] = defaultTarget
	if len(req.Arguments) > 3 {
		params["targets"] = req.Arguments[3]
	}

	if len(req.Arguments) > 4 {
		params["result"] = req.Arguments[4]
	}

	p := params.AsUrlValues()
	s := napping.Session{}
	j := BuildJSON{}
	r, err := s.Get(url, &p, &j, nil)
	if err != nil {
		return err
	}
	if r.Status() != 200 {
		return fmt.Errorf("expect response status code 200. Actual %d %s", r.Status(), params)
	}
	if len(j.Objects) == 0 {
		return fmt.Errorf("build %s/%s not found", params["build__branch"], params["targets"])
	}
	if len(j.Objects) > 1 {
		return fmt.Errorf("expected one object. Actual %d %s", len(j.Objects), params)
	}

	t := comm.Mention(req.User)
	t += fmt.Sprintf("latest *%s/%s* ", j.Objects[0].Build.Branch, j.Objects[0].Targets)
	t += fmt.Sprintf("status is *%s* ", j.Objects[0].Result)
	t += fmt.Sprintf("(%s)", comm.BuildwebSbURL(j.Objects[0].SbBuildID, strconv.Itoa(j.Objects[0].SbBuildID)))

	iop := &comm.Interop{
		Request: req,
		Response: &comm.Response{
			Channel:    req.Channel,
			Text:       t,
			Parameters: comm.DefaultMessageParameters()}}
	comm.SB.ChanResponse <- iop.Response
	comm.SB.ChanPersist <- iop

	return nil
}
Ejemplo n.º 7
0
// Handle welcome message
func (plugin *welcome) Handle(req *comm.Request) error {
	t := comm.Mention(req.User)
	m := strings.ToLower(req.Arguments[0])
	m = replacer.Replace(m)
	r, _ := responseMap[m]
	t += fmt.Sprintf("%s", r)

	comm.SB.ChanResponse <- &comm.Response{
		Channel:    req.Channel,
		Text:       t,
		Parameters: comm.DefaultMessageParameters()}

	return nil
}
Ejemplo n.º 8
0
// Handle uptime message
func (plugin *uptime) Handle(req *comm.Request) error {
	now := time.Now()

	t := comm.Mention(req.User)
	t += fmt.Sprintf(
		"start time: *%s* current time: *%s* uptime: *%s*",
		plugin.start.Format(time.RFC822),
		now.Format(time.RFC822),
		now.Sub(plugin.start))

	comm.SB.ChanResponse <- &comm.Response{
		Channel:    req.Channel,
		Text:       t,
		Parameters: comm.DefaultMessageParameters()}

	return nil
}
Ejemplo n.º 9
0
// HandleHelp checks if help is requested
func (pm *PluginManager) HandleHelp(req *comm.Request) error {
	text := comm.Mention(req.User)
	text += "*vR Ops Bot Usage*\n"
	for _, v := range pm.pullPlugin {
		u := v.Usage()
		if len(u) > 0 {
			text += fmt.Sprintf("\t%s\n", v.Usage())
		}
	}

	comm.SB.ChanResponse <- &comm.Response{
		Channel:    req.Channel,
		Text:       text,
		Parameters: comm.DefaultMessageParameters()}

	return nil
}
Ejemplo n.º 10
0
// Handle slas message
func (plugin *slas) Handle(req *comm.Request) error {
	t := comm.Mention(req.User)

	if len(plugin.config.SLAs) < 1 {
		t += "no known slas"
	} else {
		t += fmt.Sprintf("known slas - *%s*", strings.Join(plugin.config.SLAs, ", "))
	}

	iop := &comm.Interop{
		Request: req,
		Response: &comm.Response{
			Channel:    req.Channel,
			Text:       t,
			Parameters: comm.DefaultMessageParameters()}}
	comm.SB.ChanResponse <- iop.Response
	comm.SB.ChanPersist <- iop

	return nil
}
Ejemplo n.º 11
0
// Handle manages the posting of a new vro workflow
// GET https://10.25.37.28:8281/vco/api/workflows/
// POST https://10.25.37.28:8281/vco/api/workflows/<id>/executions
func (plugin *wf) Handle(req *comm.Request) error {
	vroURL := plugin.config.Vro.BaseURL + plugin.config.Vro.WfURL
	vroUser := plugin.config.Vro.Username
	vroPass := plugin.config.Vro.Password
	vroInsecure := plugin.config.Vro.Insecure
	debug := plugin.config.Debug

	build := req.Arguments[2]

	buildType := "sb"
	if len(req.Arguments) > 3 {
		buildType = req.Arguments[3]
	}

	wfName := "dev_checkin_tests"
	if len(req.Arguments) > 4 {
		wfName = req.Arguments[4]
	}

	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: vroInsecure},
	}
	s := napping.Session{
		Client:   &http.Client{Transport: tr},
		Log:      debug,
		Userinfo: url.UserPassword(vroUser, vroPass)}

	var href string
	{
		np := napping.Params{
			"conditions": fmt.Sprintf("name=%s", wfName)}
		p := np.AsUrlValues()
		j := WorkflowsJSON{}
		r, err := s.Get(vroURL, &p, &j, nil)
		if err != nil {
			return err
		}
		if r.Status() != 200 {
			return fmt.Errorf("error querying vRO for '%s' [%d]", wfName, r.Status())
		}
		if len(j.Link) == 0 {
			return fmt.Errorf("vRO workflow '%s' not found", wfName)
		}
		if len(j.Link) != 1 {
			return fmt.Errorf("expect one vRO %s workflow. Actual %d", wfName, len(j.Link))
		}
		if len(j.Link[0].Href) == 0 {
			return fmt.Errorf("href is empty for '%s' vRO workflow", wfName)
		}
		href = j.Link[0].Href
	}

	{
		slackUser, _ := comm.GetUser(req.User)
		slackEmail := fmt.Sprintf("*****@*****.**", slackUser)

		j := WorkflowExecutionJSON{
			Parameters: []Parameter{
				Parameter{
					Name: "vcopssuitepakBuildNumber",
					Type: "string",
					Value: Value{
						String: String{
							Value: build}}},
				Parameter{
					Name: "vcopssuitepakBuildType",
					Type: "string",
					Value: Value{
						String: String{
							Value: buildType}}},
				Parameter{
					Name: "email_to_address",
					Type: "string",
					Value: Value{
						String: String{
							Value: slackEmail}}},
				Parameter{
					Name: "vappPrefix",
					Type: "string",
					Value: Value{
						String: String{
							Value: slackUser}}},
				Parameter{
					Name: "vAppOwner",
					Type: "string",
					Value: Value{
						String: String{
							Value: slackUser}}}}}

		r, err := s.Post(href+"executions", &j, nil, nil)
		if err != nil {
			return err
		}
		if r.Status() != 202 {
			return fmt.Errorf("expect response status code 202. Actual %d", r.Status())
		}
	}

	text := comm.Mention(req.User)
	text += fmt.Sprintf("started vro workflow *%s* using *%s/%s*",
		wfName, build, buildType)

	iop := &comm.Interop{
		Request: req,
		Response: &comm.Response{
			Channel:    req.Channel,
			Text:       text,
			Parameters: comm.DefaultMessageParameters()}}
	comm.SB.ChanResponse <- iop.Response
	comm.SB.ChanPersist <- iop

	return nil
}
Ejemplo n.º 12
0
// Handle recommended message
// CAT URL:
// http://cat.eng.vmware.com/api/v2.0/recommendation/?format=json&limit=1&order_by=-updated&branch__name=main&sla__name=VA_Bats&site=mbu
func (plugin *recommended) Handle(req *comm.Request) error {
	branch := defaultBranch
	if len(req.Arguments) > 2 {
		branch = req.Arguments[2]
	}

	jRecommended := RecommendedJSON{}
	{
		url := plugin.config.URLs.BaseCatURL + plugin.config.URLs.BaseRecommendedURL
		params := DefaultRecommendedParams()
		params["branch__name"] = branch

		p := params.AsUrlValues()
		s := napping.Session{}
		r, err := s.Get(url, &p, &jRecommended, nil)
		if err != nil {
			return err
		}
		if r.Status() != 200 {
			return fmt.Errorf("expect response status code 200. Actual %d %s", r.Status(), params)
		}
		if len(jRecommended.Objects) == 0 {
			return fmt.Errorf("recommended change list for %s not found", params["branch__name"])
		}
		if len(jRecommended.Objects) > 1 {
			return fmt.Errorf("expected one object. Actual %d %s", len(jRecommended.Objects), params)
		}
	}

	// CAT URL:
	// http://cat.eng.vmware.com/api/v2.0/build/<id>/?format=json
	jCurrBuild := CurrBuildJSON{}
	{
		url := plugin.config.URLs.BaseCatURL + jRecommended.Objects[0].CurrBuild
		params := DefaultCurrBuildParams()

		p := params.AsUrlValues()
		s := napping.Session{}
		r, err := s.Get(url, &p, &jCurrBuild, nil)
		if err != nil {
			return err
		}
		if r.Status() != 200 {
			return fmt.Errorf("expect response status code 200. Actual %d\n", r.Status())
		}
	}

	t := comm.Mention(req.User)
	t += fmt.Sprintf("recommended changeset for *%s* ", branch)
	t += fmt.Sprintf("is *%s*", comm.P4WebBranchURL(branch, jCurrBuild.Changeset))

	iop := &comm.Interop{
		Request: req,
		Response: &comm.Response{
			Channel:    req.Channel,
			Text:       t,
			Parameters: comm.DefaultMessageParameters()}}
	comm.SB.ChanResponse <- iop.Response
	comm.SB.ChanPersist <- iop

	return nil
}