diff --git a/conflicts_getter.go b/conflicts_getter.go new file mode 100644 index 0000000..74d0e45 --- /dev/null +++ b/conflicts_getter.go @@ -0,0 +1,53 @@ +package main + +import ( + "errors" + "io" + "net/http" +) + +func getRdbData(task string) ([]byte, error) { + resp, err := http.Get( + "https://rdb.altlinux.org/api/task/misconflict/" + task) + if err != nil { + return []byte{}, err + } + + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + if err != nil { + return []byte{}, err + } + return body, nil +} + +func getConflicts(unmData interface{}) (map[string][]string, error) { + result := make(map[string][]string) + confilcts, ok := unmData.(map[string]interface{})["conflicts"] + if !ok { + return result, errors.New( + "Can't convert umarshal data to map[string]interface{}") + } + + for _, rowConflict := range confilcts.([]interface{}) { + err := processeConflict(result, rowConflict) + if err != nil { + return result, err + } + } + return result, nil +} + +func processeConflict( + result map[string][]string, rowConflict interface{}) error { + conflict, ok := rowConflict.(map[string]interface{}) + if !ok { + return errors.New( + "Can't processed conflict data") + } + + inputPackage := conflict["input_package"].(string) + conflictPackage := conflict["conflict_package"].(string) + result[inputPackage] = append(result[inputPackage], conflictPackage) + return nil +}