Example #1
0
File: yaml.go Project: gosexy/yaml
/*
	Returns a YAML setting
*/
func (self *Yaml) Get(route ...interface{}) interface{} {
	var i interface{}

	if Compat == true {
		// Compatibility should be removed soon.
		if len(route) == 1 {
			p := route[0].(string)

			if strings.Contains(p, "/") == true {
				p := strings.Split(p, "/")

				route := make([]interface{}, len(p))

				for i, _ := range p {
					route[i] = p[i]
				}

				log.Printf(`Using a route separated by "/" is deprecated, please use yaml.*Yaml.Get("%s") instead.`, strings.Join(p, `", "`))

				dig.Get(&self.values, &i, route...)
				return i
			}
		}
	}

	dig.Get(&self.values, &i, route...)
	return i
}
Example #2
0
func (a *ABF) makePkgList(json map[string]interface{}) []models.ListArtifact {
	var pkgs []interface{}
	dig.Get(&json, &pkgs, "packages")

	var pkg []models.ListArtifact

	pkgrep := func(m map[string]interface{}) models.ListArtifact {
		pkgType := dig.String(&m, "type")
		if strings.HasSuffix(dig.String(&m, "name"), "-debuginfo") {
			pkgType = "debuginfo"
		}

		return models.ListArtifact{
			Name:    dig.String(&m, "name"),
			Type:    pkgType,
			Epoch:   dig.Int64(&m, "epoch"),
			Version: dig.String(&m, "version"),
			Release: dig.String(&m, "release"),
			Variant: dig.String(&json, "arch", "name"),
			URL:     dig.String(&m, "url"),
		}
	}

	for _, v := range pkgs {
		asserted := v.(map[string]interface{})
		pkg = append(pkg, pkgrep(asserted))
	}

	return pkg
}
Example #3
0
func (a *ABF) makeBuildList(list map[string]interface{}) (*models.List, error) {
	pkg := a.makePkgList(list)

	changelog := ""

	var logs []interface{}
	dig.Get(&list, &logs, "logs")

	for _, v := range logs {
		asserted := v.(map[string]interface{})
		if dig.String(&asserted, "file_name") == "changelog.log" {
			changelog = dig.String(&asserted, "url")
			break
		}
	}

	handleID := to.String(dig.Uint64(&list, "id"))
	handleProject := dig.String(&list, "project", "fullname")
	platform := dig.String(&list, "save_to_repository", "platform", "name")

	bl := models.List{
		Name:     dig.String(&list, "project", "name"),
		Platform: platform,
		Channel:  dig.String(&list, "save_to_repository", "name"),
		Variants: dig.String(&list, "arch", "name"),

		Artifacts: pkg,
		Links: []models.ListLink{
			{
				Name: models.LinkMain,
				URL:  fmt.Sprintf("%s/build_lists/%v", abfURL, handleID),
			},
			{
				Name: models.LinkChangelog,
				URL:  changelog,
			},
			{
				Name: models.LinkSCM,
				URL:  fmt.Sprintf("%s/%v/commits/%v", abfURL, handleProject, platform),
			},
		},
		Changes:   changelog,
		BuildDate: time.Unix(dig.Int64(&list, "updated_at"), 0),

		StageCurrent: models.ListStageNotStarted,
		StageResult:  models.ListRunning,
		Activity: []models.ListActivity{
			{
				UserID:   models.FindUser(models.UserSystem).ID,
				Activity: "Imported this build list from ABF.",
			},
		},

		IntegrationName: "abf",
		IntegrationOne:  "[" + handleID + "]",
		IntegrationTwo:  dig.String(&list, "commit_hash"),
	}

	return &bl, nil
}
Example #4
0
func (a *ABF) getJSONList(id uint64) (list map[string]interface{}, err error) {
	req, err := http.NewRequest("GET", abfURL+"/api/v1/build_lists/"+to.String(id)+".json", nil)
	if err != nil {
		return
	}

	req.SetBasicAuth(abfUser, abfAPIKey)

	resp, err := abfClient.Do(req)
	if err != nil {
		return
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return
	}

	var result map[string]interface{}

	err = json.Unmarshal(body, &result)
	if err != nil {
		return
	}

	dig.Get(&result, &list, "build_list")
	return
}
Example #5
0
func (a *ABF) handleResponse(resp *http.Response, testing bool) error {

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	var result map[string]interface{}

	err = json.Unmarshal(body, &result)
	if err != nil {
		return err
	}

	var lists []interface{}

	err = dig.Get(&result, &lists, "build_lists")
	if err != nil {
		return err
	}

	for _, v := range lists {
		asserted := v.(map[string]interface{})
		id := dig.Uint64(&asserted, "id")
		strID := "[" + to.String(id) + "]"

		var num int
		err = models.DB.Model(&models.List{}).Where("integration_name = ? AND integration_one LIKE ?", "abf", "%"+strID+"%").Count(&num).Error
		if err != nil && err != gorm.ErrRecordNotFound {
			klog.Criticalf("abf: couldn't check db for existing (list %v): %v", id, err)
			continue
		}

		if num != 0 {
			klog.Infof("abf: ignoring list, already processed (list %v)", id)
			continue
		}

		json, err := a.getJSONList(id)
		if err != nil {
			klog.Criticalf("abf: couldn't retrieve the build list JSON (list %v): %v", id, err)
			continue
		}

		// check if arch is on whitelist
		if abfArchWhitelistSet != nil && !abfArchWhitelistSet.Contains(dig.String(&json, "arch", "name")) {
			klog.Infof("abf: ignoring list, arch not on whitelist (list %v)", id)
			continue
		}

		// check if platform is on whitelist
		if !abfPlatformsSet.Contains(dig.String(&json, "save_to_repository", "platform", "name")) {
			klog.Infof("abf: ignoring list, platform not on whitelist (list %v)", id)
			continue
		}

		// *check for duplicates before continuing
		// *we only check for duplicates in the same platform; different platforms have different conditions

		// check for duplicates
		var duplicate models.List
		err = models.DB.Where("platform = ? AND integration_two = ? AND stage_current <> ?",
			dig.String(&json, "save_to_repository", "platform", "name"),
			dig.String(&json, "commit_hash"),
			models.ListStageFinished).First(&duplicate).Error

		if err != nil && err != gorm.ErrRecordNotFound {
			klog.Criticalf("abf: couldn't check db for duplicates (list %v): %v", id, err)
			continue
		}

		if err == nil { // we had no problem finding a duplicate, so handle and continue
			duplicate.IntegrationOne += ";" + strID
			duplicate.Variants += ";" + dig.String(&json, "arch", "name")

			if testing { // we got this from the build completed (not in testing) list
				// send id to testing
				go a.sendToTesting(id)
			}

			err = models.DB.Save(&duplicate).Error
			if err != nil {
				klog.Criticalf("abf: couldn't save duplicate modification to %v (list %v): %v", duplicate.ID, id, err)
			}

			pkgs := a.makePkgList(json)
			for _, listpkg := range pkgs {
				listpkg.ListID = duplicate.ID

				err = models.DB.Create(&listpkg).Error
				if err != nil {
					klog.Criticalf("abf: couldn't save new list package to %v (list %v): %v", duplicate.ID, id, err)
				}
			}

			// add a link to it
			newLink := models.ListLink{
				ListID: duplicate.ID,
				Name:   fmt.Sprintf("Build List for %v", dig.String(&json, "arch", "name")),
				URL:    fmt.Sprintf("%s/build_lists/%v", abfURL, id),
			}
			if err := models.DB.Create(&newLink).Error; err != nil {
				klog.Criticalf("abf: couldn't save new list link to %v (list %v): %v", duplicate.ID, id, err)
			}

			// ok, we're done here
			continue
		}

		list, err := a.makeBuildList(json)
		if err != nil {
			klog.Criticalf("abf: couldn't make new list (list %v): %v\n", id, err)
			continue
		}

		if testing {
			// Now send it to testing
			go a.sendToTesting(id)
		}

		if err := models.DB.Create(list).Error; err != nil {
			klog.Criticalf("abf: couldn't create new list in db (list %v): %v", id, err)
			continue
		}
	}

	return nil
}