mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-29 18:38:32 +08:00
🐞 fix(server): gogs 仓库令牌导入异常
This commit is contained in:
parent
23516eb54a
commit
393ce2d89c
@ -1,9 +1,14 @@
|
||||
# 🚀 版本日志
|
||||
|
||||
## 2.11.6.2-beta
|
||||
## 2.11.6.3-beta
|
||||
|
||||
### 🐣 新增功能
|
||||
### 🐞 解决BUG、优化功能
|
||||
|
||||
1. 【server】修复 gogs 仓库令牌导入异常(感谢@张飞鸿)
|
||||
|
||||
------
|
||||
|
||||
## 2.11.6.2-beta (2024-06-06)
|
||||
|
||||
### 🐞 解决BUG、优化功能
|
||||
|
||||
|
@ -376,29 +376,31 @@ public class RepositoryController extends BaseServerController {
|
||||
@GetMapping(value = "/build/repository/authorize_repos")
|
||||
@Feature(method = MethodFeature.LIST)
|
||||
public IJsonMessage<PageResultDto<JSONObject>> authorizeRepos(HttpServletRequest request,
|
||||
@ValidatorItem String token,
|
||||
String address,
|
||||
@ValidatorItem String type,
|
||||
String condition) {
|
||||
@ValidatorItem String token,
|
||||
String address,
|
||||
@ValidatorItem String type,
|
||||
String condition) {
|
||||
// 获取分页信息
|
||||
Map<String, String> paramMap = ServletUtil.getParamMap(request);
|
||||
Page page = repositoryService.parsePage(paramMap);
|
||||
Assert.hasText(token, "请填写个人令牌");
|
||||
// 搜索条件
|
||||
// 远程仓库
|
||||
PageResultDto<JSONObject> pageResultDto;
|
||||
ImportRepoUtil.getProviderConfig(type);
|
||||
//ImportRepoUtil.getProviderConfig(type);
|
||||
|
||||
String userName = ImportRepoUtil.getCurrentUserName(type, token, address);
|
||||
cn.hutool.json.JSONObject repoList = ImportRepoUtil.getRepoList(type, condition, page, token, userName, address);
|
||||
pageResultDto = new PageResultDto<>(page.getPageNumber(), page.getPageSize(), repoList.getLong("total").intValue());
|
||||
List<JSONObject> objects = repoList.getJSONArray("data").stream().map(o -> {
|
||||
cn.hutool.json.JSONObject obj = (cn.hutool.json.JSONObject) o;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.putAll(obj);
|
||||
jsonObject.put("exists", RepositoryController.this.checkRepositoryUrl(obj.getStr("url"), request));
|
||||
return jsonObject;
|
||||
}).collect(Collectors.toList());
|
||||
PageResultDto<JSONObject> pageResultDto = new PageResultDto<>(page.getPageNumber(), page.getPageSize(), repoList.getLong("total").intValue());
|
||||
List<JSONObject> objects = repoList.getJSONArray("data")
|
||||
.stream()
|
||||
.map(o -> {
|
||||
cn.hutool.json.JSONObject obj = (cn.hutool.json.JSONObject) o;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.putAll(obj);
|
||||
jsonObject.put("exists", RepositoryController.this.checkRepositoryUrl(obj.getStr("url"), request));
|
||||
return jsonObject;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
pageResultDto.setResult(objects);
|
||||
return JsonMessage.success(HttpStatus.OK.name(), pageResultDto);
|
||||
}
|
||||
@ -525,8 +527,8 @@ public class RepositoryController extends BaseServerController {
|
||||
@GetMapping(value = "/build/repository/sort-item", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Feature(method = MethodFeature.EDIT)
|
||||
public IJsonMessage<String> sortItem(@ValidatorItem String id,
|
||||
@ValidatorItem String method,
|
||||
String compareId, HttpServletRequest request) {
|
||||
@ValidatorItem String method,
|
||||
String compareId, HttpServletRequest request) {
|
||||
if (StrUtil.equalsIgnoreCase(method, "top")) {
|
||||
repositoryService.sortToTop(id, request);
|
||||
} else if (StrUtil.equalsIgnoreCase(method, "up")) {
|
||||
|
@ -52,23 +52,23 @@ public class ImportRepoUtil {
|
||||
public Map<String, Map<String, Object>> getProviderList() {
|
||||
Resource[] configResources = ExtConfigBean.getConfigResources("import-repo-provider/*.yml");
|
||||
return Arrays.stream(configResources)
|
||||
.map(resource -> {
|
||||
String filename = resource.getFilename();
|
||||
String mainName = FileUtil.mainName(filename);
|
||||
.map(resource -> {
|
||||
String filename = resource.getFilename();
|
||||
String mainName = FileUtil.mainName(filename);
|
||||
|
||||
try (InputStream inputStream = resource.getInputStream()) {
|
||||
ImportRepoProviderConfig providerConfig = YamlUtil.load(inputStream, ImportRepoProviderConfig.class);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", mainName);
|
||||
map.put("baseUrl", providerConfig.getBaseUrl());
|
||||
// 是否支持查询
|
||||
map.put("query", providerConfig.getRepoListParam().values().stream().anyMatch(s -> s.contains("${query}")));
|
||||
return map;
|
||||
} catch (Exception e) {
|
||||
throw Lombok.sneakyThrow(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toMap(map -> (String) map.get("name"), map -> map));
|
||||
try (InputStream inputStream = resource.getInputStream()) {
|
||||
ImportRepoProviderConfig providerConfig = YamlUtil.load(inputStream, ImportRepoProviderConfig.class);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", mainName);
|
||||
map.put("baseUrl", providerConfig.getBaseUrl());
|
||||
// 是否支持查询
|
||||
map.put("query", providerConfig.getRepoListParam().values().stream().anyMatch(s -> s.contains("${query}")));
|
||||
return map;
|
||||
} catch (Exception e) {
|
||||
throw Lombok.sneakyThrow(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toMap(map -> (String) map.get("name"), map -> map));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@ -186,12 +186,12 @@ public class ImportRepoUtil {
|
||||
HttpRequest request = HttpUtil.createRequest(Method.valueOf(provider.getCurrentUserMethod()), baseUrl + provider.getCurrentUserUrl());
|
||||
setCommonParams(platform, request, token);
|
||||
String body;
|
||||
log.debug(String.format("url: %s headers: %s form: %s", request.getUrl(), request.headers(), request.form()));
|
||||
log.debug("url: {} headers: {} form: {}", request.getUrl(), request.headers(), request.form());
|
||||
try (HttpResponse execute = request.execute()) {
|
||||
body = execute.body();
|
||||
int status = execute.getStatus();
|
||||
Map<String, List<String>> headers = execute.headers();
|
||||
log.debug(String.format("status: %s body: %s headers: %s", status, body, headers));
|
||||
log.debug("status: {} body: {} headers: {}", status, body, headers);
|
||||
Assert.state(execute.isOk(), String.format("请求失败: status: %s body: %s headers: %s", status, body, headers));
|
||||
}
|
||||
return JSONUtil.parse(body).getByPath(provider.getUserNamePath(), String.class);
|
||||
|
@ -11,7 +11,7 @@
|
||||
baseUrl: https://try.gogs.io
|
||||
authType: 1
|
||||
authKey: Authorization
|
||||
authValue: 'Bearer ${token}'
|
||||
authValue: 'token ${token}'
|
||||
currentUserMethod: GET
|
||||
currentUserUrl: /api/v1/user
|
||||
userNamePath: login
|
||||
|
Loading…
Reference in New Issue
Block a user