|
|
|
@@ -513,24 +513,37 @@ func NotFound(ctx *context.Context) { |
|
|
|
ctx.Data["Title"] = "Page Not Found" |
|
|
|
ctx.NotFound("home.NotFound", nil) |
|
|
|
} |
|
|
|
|
|
|
|
func RecommendOrgFromPromote(ctx *context.Context) { |
|
|
|
url := setting.RecommentRepoAddr + "organizations" |
|
|
|
recommendFromPromote(ctx, url) |
|
|
|
result, err := recommendFromPromote(url) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("500", err) |
|
|
|
return |
|
|
|
} |
|
|
|
resultOrg := make([]*models.User, 0) |
|
|
|
for i, userName := range result { |
|
|
|
user, err := models.GetUserByName(userName) |
|
|
|
if err == nil { |
|
|
|
resultOrg[i] = user |
|
|
|
} else { |
|
|
|
log.Info("query user error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.JSON(200, resultOrg) |
|
|
|
} |
|
|
|
|
|
|
|
func recommendFromPromote(ctx *context.Context, url string) []string { |
|
|
|
func recommendFromPromote(url string) ([]string, error) { |
|
|
|
resp, err := http.Get(url) |
|
|
|
if err != nil { |
|
|
|
log.Info("Get organizations url error=" + err.Error()) |
|
|
|
ctx.ServerError("Get organizations url error:", err) |
|
|
|
return nil |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
bytes, err := ioutil.ReadAll(resp.Body) |
|
|
|
resp.Body.Close() |
|
|
|
if err != nil { |
|
|
|
log.Info("Get organizations url error=" + err.Error()) |
|
|
|
ctx.ServerError("Read organizations url error:", err) |
|
|
|
return nil |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
allLineStr := string(bytes) |
|
|
|
@@ -546,11 +559,31 @@ func recommendFromPromote(ctx *context.Context, url string) []string { |
|
|
|
result[i] = strings.Trim(line[tmpIndex+1:], " ") |
|
|
|
} |
|
|
|
} |
|
|
|
return result |
|
|
|
return result, nil |
|
|
|
} |
|
|
|
|
|
|
|
func RecommendRepoFromPromote(ctx *context.Context) { |
|
|
|
url := setting.RecommentRepoAddr + "projects" |
|
|
|
recommendFromPromote(ctx, url) |
|
|
|
|
|
|
|
result, err := recommendFromPromote(url) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("500", err) |
|
|
|
return |
|
|
|
} |
|
|
|
resultRepo := make([]*models.Repository, 0) |
|
|
|
for i, repoName := range result { |
|
|
|
tmpIndex := strings.Index(repoName, ".") |
|
|
|
if tmpIndex == -1 { |
|
|
|
log.Info("error repo name format.") |
|
|
|
} else { |
|
|
|
ownerName := repoName[0:tmpIndex] |
|
|
|
repoName := repoName[tmpIndex+1:] |
|
|
|
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName) |
|
|
|
if err == nil { |
|
|
|
resultRepo[i] = repo |
|
|
|
} else { |
|
|
|
log.Info("query repo error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.JSON(200, resultRepo) |
|
|
|
} |