Skip to content

Commit

Permalink
增dws contribute字段和测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaede10 committed Feb 8, 2025
1 parent 922ca8b commit fdd4bc7
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.1</version>
<version>42.7.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public static ContributeDO toEntity(final BaseContribute obj) {
contrib.setClosedAt(obj.getClosedAt());
contrib.setState(obj.getState());
contrib.setClosedTime(DateUtil.getDuration(obj.getCreatedAt(), obj.getClosedAt()));
contrib.setIsRemoved(obj.getIsRemoved());
contrib.setVersion(null);
return contrib;
}

Expand Down Expand Up @@ -89,6 +91,7 @@ public static ContributeDO toEntity(final PRDO obj, BaseContribute baseContirb)
contrib.setMergedAt(obj.getMergedAt());
contrib.setAdd(obj.getAddedLines());
contrib.setRemove(obj.getRemovedLines());
contrib.setBranch(obj.getBaseLabel());
contrib.setIsPr(1);
contrib.setContribType(ContribConstant.PR);
return contrib;
Expand All @@ -106,6 +109,7 @@ public static ContributeDO toEntity(final CommentDO obj, BaseContribute baseCont
contrib.setUuid(obj.getUuid());
contrib.setBody(obj.getBody());
contrib.setIsComment(1);
contrib.setCommentType(obj.getCommentType());
contrib.setContribType(ContribConstant.COMMENT);
return contrib;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class CommentDO {
private String uuid;

/**
* comment is.
* comment id.
*/
@TableField("id")
private String id;
Expand Down Expand Up @@ -116,4 +116,10 @@ public class CommentDO {
*/
@TableField("repo_path")
private String repoPath;

/**
* the comment isRemoved.
*/
@TableField("is_removed")
private String isRemoved;
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,10 @@ public class IssueDO {
*/
@TableField("code_platform")
private String codePlatform;

/**
* the issue isRemoved.
*/
@TableField("is_removed")
private String isRemoved;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ public class ContributeDO {
@TableField("code_platform")
private String codePlatform;

/**
* The version of a contribute.
*/
private String version;

/**
* The branch of a pr.
*/
private String branch;

/**
* The title of a pr or issue.
*/
Expand Down Expand Up @@ -175,6 +185,12 @@ public class ContributeDO {
@TableField("closed_time")
private Long closedTime;

/**
* The comment type of a comment.
*/
@TableField("comment_type")
private String commentType;

/**
* Indicate whether the contribute is a pr.
*/
Expand Down Expand Up @@ -204,4 +220,10 @@ public class ContributeDO {
*/
@TableField("remove")
private Long remove;

/**
* the contribute isRemoved.
*/
@TableField("is_removed")
private String isRemoved;
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public class BaseContribute {
*/
private String contribType;

/**
* The comment type of a comment.
*/
private String commentType;

/**
* The first reply time of a pr or issue.
*/
Expand All @@ -118,4 +123,9 @@ public class BaseContribute {
* The closed duration time of a pr or issue.
*/
private Long closedTime;

/**
* The contribute isRemoved.
*/
private String isRemoved;
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public void run() {
}

/**
* @param robots Compose DWS Issue.
* Compose DWS Issue.
*
* @param robots Login of robot.
*/
public void composeIssue(List<String> robots) {
List<IssueDO> doList = issueService.list();
Expand All @@ -111,9 +113,10 @@ public void composeIssue(List<String> robots) {
contributeService.saveOrUpdateBatch(items);
}


/**
* @param robots Compose DWS PR.
* Compose DWS PR.
*
* @param robots Login of robot.
*/
public void composePR(List<String> robots) {
List<PRDO> doList = prService.list();
Expand Down Expand Up @@ -156,7 +159,7 @@ public void composeComment() {
/**
* Compute comment num of a pr or issue.
*
* @param robots
* @param robots Login of robot
* @param htmlUrl The html url for pr or issue
* @return comment num
*/
Expand All @@ -172,7 +175,7 @@ public Integer computeCommentNum(String htmlUrl, List<String> robots) {
/**
* Get first comment of a pr or issue.
*
* @param robots
* @param robots Login of robot
* @param htmlUrl The html url for pr or issue.
* @return A comment.
*/
Expand All @@ -191,7 +194,7 @@ public CommentDO getFirstComment(String htmlUrl, List<String> robots) {
/**
* Compute comment num of a pr or issue.
*
* @param robots
* @param robots Login of robot
* @param obj The BaseContribute object
* @return The first reply time of a pr or issue
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
This project is licensed under the Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
Created: 2025
*/
package com.om.DataMagic.process.codePlatform.gitcode.dws.contribute;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.JsonNode;
import com.om.DataMagic.common.util.ObjectMapperUtil;
import com.om.DataMagic.infrastructure.pgDB.converter.IssueConverter;
import com.om.DataMagic.infrastructure.pgDB.converter.PRConverter;
import com.om.DataMagic.infrastructure.pgDB.dataobject.CommentDO;
import com.om.DataMagic.infrastructure.pgDB.dataobject.IssueDO;
import com.om.DataMagic.infrastructure.pgDB.dataobject.PRDO;
import com.om.DataMagic.infrastructure.pgDB.service.CommentService;
import com.om.DataMagic.infrastructure.pgDB.service.IssueService;
import com.om.DataMagic.infrastructure.pgDB.service.PRService;
import com.om.DataMagic.infrastructure.pgDB.service.dws.ContributeService;
import com.om.DataMagic.infrastructure.pgDB.service.dws.UserService;

@ExtendWith(MockitoExtension.class)
public class GitCodeContributeProcessTest {
@Test
void contextLoads() {
}

@Mock
private UserService userService;

@Mock
private PRService prService;

@Mock
private IssueService issueService;

@Mock
private CommentService commentService;

@Mock
private ContributeService contributeService;

@InjectMocks
private GitCodeContributeProcess process;

@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
}

@Test()
void testComposePR() throws Exception {
when(contributeService.saveOrUpdateBatch(anyCollection())).thenReturn(true);

PRConverter prConverter = new PRConverter();
JsonNode pr = ObjectMapperUtil.toJsonNode(getPRList());
List<PRDO> prs = new ArrayList<>();
prs.add(prConverter.toDO(pr));
when(prService.list()).thenReturn(prs);

List<String> robots = Arrays.asList("opengauss-bot");
when(commentService.count(any(QueryWrapper.class))).thenReturn(5l);
IPage<CommentDO> page = new Page<>();
when(commentService.page(any(IPage.class), any(QueryWrapper.class))).thenReturn(page);
process.composePR(robots);
}

@Test()
void testComposeIssue() throws Exception {
when(contributeService.saveOrUpdateBatch(anyCollection())).thenReturn(true);

IssueConverter converter = new IssueConverter();
JsonNode issue = ObjectMapperUtil.toJsonNode(getIssueList());
List<IssueDO> issues = new ArrayList<>();
issues.add(converter.toDO(issue));
when(issueService.list()).thenReturn(issues);

List<String> robots = Arrays.asList("opengauss-bot");
when(commentService.count(any(QueryWrapper.class))).thenReturn(5l);
IPage<CommentDO> page = new Page<>();
when(commentService.page(any(IPage.class), any(QueryWrapper.class))).thenReturn(page);
process.composeIssue(robots);
}

public String getPRList() {
return "{\n" +
" \"uuid\": \"gitcode-6499048\",\n" +
" \"id\": \"6499048\",\n" +
" \"number\": \"249\",\n" +
" \"url\": \"https://gitcode.com/api/v5/repos/opengaussmirror202502/infra/pulls/249\",\n" +
" \"html_url\": \"https://gitcode.com/opengaussmirror202502/infra/merge_requests/249\",\n" +
" \"title\": \"close monitor agent\",\n" +
" \"body\": \"\",\n" +
" \"created_at\": \"2024-06-19T09:47:36+08:00\",\n" +
" \"updated_at\": \"2024-06-19T09:47:36+08:00\",\n" +
" \"closed_at\": \"2024-06-19T09:47:36+08:00\",\n" +
" \"merged_at\": \"2024-06-19T09:47:36+08:00\",\n" +
" \"user_login\": \"liuyanglinux\",\n" +
" \"state\": \"merged\",\n" +
" \"assignees_user_ids\": \"[]\",\n" +
" \"labels_id\": \"[\\\"13022923\\\",\\\"13022921\\\",\\\"13021416\\\"]\",\n" +
" \"labels_name\": \"[\\\"needs-issue\\\",\\\"opengauss-cla/yes\\\",\\\"sig/infra\\\"]\",\n" +
" \"head_label\": \"liuyang02\",\n" +
" \"head_ref\": \"liuyang02\",\n" +
" \"head_user_id\": \"64e5ed8f7e20aa73efcbc302\",\n" +
" \"head_user_login\": \"gitcode-xxm\",\n" +
" \"head_repo_id\": \"4579472\",\n" +
" \"head_repo_path\": \"infra\",\n" +
" \"head_repo_full_name\": \"opengaussmirror202502/infra\",\n" +
" \"base_label\": \"master\",\n" +
" \"base_ref\": \"master\",\n" +
" \"base_user_id\": \"64e5ed8f7e20aa73efcbc302\",\n" +
" \"base_user_login\": \"gitcode-xxm\",\n" +
" \"base_repo_id\": \"4579472\",\n" +
" \"repo_name\": \"infra\",\n" +
" \"repo_path\": \"infra\",\n" +
" \"base_owner_user_id\": \"64e5ed8f7e20aa73efcbc302\",\n" +
" \"base_owner_user_login\": \"gitcode-xxm\",\n" +
" \"private\": \"\",\n" +
" \"internal\": \"\",\n" +
" \"fork\": null,\n" +
" \"namespace\": \"opengaussmirror202502\",\n" +
" \"code_platform\": \"gitcode\",\n" +
" \"is_removed\": null,\n" +
" \"added_lines\": null,\n" +
" \"removed_lines\": null\n" +
"}";
}

public String getIssueList() {
return "{\n" +
" \"uuid\": \"gitcode-2874800\",\n" +
" \"id\": \"2874800\",\n" +
" \"number\": \"25\",\n" +
" \"url\": \"\",\n" +
" \"html_url\": \"https://gitcode.com/opengaussmirror202502/infra/issues/25\",\n" +
" \"title\": \"openGauss 官网搜索引入人工智能搜索结果\",\n" +
" \"body\": \"用户进入搜索框进行文档资料搜索时****************\",\n" +
" \"created_at\": \"2024-06-19T09:47:36+08:00\",\n" +
" \"updated_at\": \"2024-06-19T09:47:36+08:00\",\n" +
" \"closed_at\": null,\n" +
" \"deadline\": null,\n" +
" \"user_login\": \"liuyanglinux\",\n" +
" \"state\": \"open\",\n" +
" \"plan_started_at\": null,\n" +
" \"labels_id\": \"[\\\"13022922\\\"]\",\n" +
" \"labels_name\": \"[\\\"sig/infra\\\"]\",\n" +
" \"assignees_user_ids\": \"\",\n" +
" \"issue_state\": \"待办的\",\n" +
" \"issue_type\": \"任务\",\n" +
" \"priority\": \"0\",\n" +
" \"program\": null,\n" +
" \"repo_id\": \"4579472\",\n" +
" \"repo_name\": \"infra\",\n" +
" \"repo_path\": \"infra\",\n" +
" \"security_hole\": \"\",\n" +
" \"namespace\": \"opengaussmirror202502\",\n" +
" \"code_platform\": \"gitcode\"\n" +
"}";
}
}

0 comments on commit fdd4bc7

Please sign in to comment.