mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
chore: Various MCP improvements
This commit is contained in:
parent
1ccdde6087
commit
b84c56da53
@ -1055,7 +1055,7 @@ public class Issue extends ProjectBelonging implements AttachmentStorageSupport
|
||||
var field = getIssueSetting().getFieldSpec(fieldName);
|
||||
if (field != null) {
|
||||
var value = getFieldValue(fieldName);
|
||||
if (value != null) {
|
||||
if (value != null && (!(value instanceof Collection) || !((Collection<?>) value).isEmpty())) {
|
||||
if (field instanceof ChoiceField) {
|
||||
var values = new ArrayList<String>();
|
||||
if (value instanceof Collection)
|
||||
|
||||
@ -1395,11 +1395,20 @@ public class PullRequest extends ProjectBelonging
|
||||
return lowerTitle.startsWith("wip") || lowerTitle.startsWith("[wip]");
|
||||
}
|
||||
|
||||
// Remove issue number suffix if there is any
|
||||
public void cleanTitle() {
|
||||
var cleanedTitle = title.replaceFirst("\\s*\\([a-zA-Z]+-\\d+\\)$", "");
|
||||
cleanedTitle = cleanedTitle.replaceFirst("\\s*\\(#\\d+\\)$", "").trim();
|
||||
if (cleanedTitle.length() != 0)
|
||||
title = cleanedTitle;
|
||||
}
|
||||
|
||||
public void generateTitleAndDescriptionIfEmpty() {
|
||||
if (title == null) {
|
||||
var commits = getLatestUpdate().getCommits();
|
||||
if (commits.size() == 1) {
|
||||
title = commits.get(0).getShortMessage();
|
||||
cleanTitle();
|
||||
} else {
|
||||
title = getSource().getBranch().toLowerCase();
|
||||
boolean wip = false;
|
||||
|
||||
@ -176,18 +176,22 @@ public class GlobalIssueSetting implements Serializable {
|
||||
inProgress.setName("In Progress");
|
||||
inProgress.setColor("#FFA700");
|
||||
inProgress.setDescription(
|
||||
"The AI assistant should switch the working directory to the branch corresponding to the issue by running below command:\n" +
|
||||
"git checkout -b <branch-name> origin/main && git push -u origin <branch-name>");
|
||||
"The AI assistant should switch the working directory to the branch corresponding to the issue by running below command:\n\n" +
|
||||
"git fetch <onedev remote> main && git checkout -b <branch-name> <onedev remote>/main && git push -u <onedev remote> <branch-name>\n\n" +
|
||||
"Here <branch name> should be derived from user instruction or issue title, and <onedev remote> should be retrieved by calling tool getCurrentRemote"
|
||||
);
|
||||
stateSpecs.add(inProgress);
|
||||
|
||||
StateSpec inReview = new StateSpec();
|
||||
inReview.setName("In Review");
|
||||
inReview.setColor("#9C26B0");
|
||||
inReview.setDescription(
|
||||
"AI assistant should do the following:\n" +
|
||||
"1. Create conventional commit for current work if there are uncommitted changes. Note that subject of the commit message should mention the issue number at the end in form of (#<issue number>)\n" +
|
||||
"2. Push the branch to remote by running \"git push\"\n" +
|
||||
"3. Create a pull request for current branch");
|
||||
"AI assistant should do the following:\n\n" +
|
||||
"1. Add files to git index, and create conventional commit for current work if there are uncommitted changes. Subject line of the commit message should include the issue number at the end in form of (<issue reference>)\n" +
|
||||
"2. Push the branch to remote by running \"git push <onedev remote>\"\n" +
|
||||
"3. Create a pull request for current branch, with other params derived from current issue, and user instruction\n\n" +
|
||||
"Here <issue reference> should be replaced with reference of the issue whose state is being changed, and <onedev remote> should be retrieved via tool getCurrentRemote"
|
||||
);
|
||||
stateSpecs.add(inReview);
|
||||
|
||||
StateSpec closed = new StateSpec();
|
||||
|
||||
@ -657,31 +657,31 @@ public class McpHelperResource {
|
||||
}
|
||||
}
|
||||
if (toStates.size() > 0) {
|
||||
var transitionInputSchema = new HashMap<String, Object>();
|
||||
transitionInputSchema.put("Type", "object");
|
||||
var changeIssueStateInputSchema = new HashMap<String, Object>();
|
||||
changeIssueStateInputSchema.put("Type", "object");
|
||||
|
||||
var transitIssueProperties = new HashMap<String, Object>();
|
||||
transitIssueProperties.put("issueReference", Map.of(
|
||||
var changeIssueStateProperties = new HashMap<String, Object>();
|
||||
changeIssueStateProperties.put("issueReference", Map.of(
|
||||
"type", "string",
|
||||
"description", "reference of the issue to transit state"));
|
||||
transitIssueProperties.put("state", Map.of(
|
||||
"description", "reference of the issue to change state"));
|
||||
changeIssueStateProperties.put("state", Map.of(
|
||||
"type", "string",
|
||||
"description", "new state of the issue after transition. Must be one of: " + String.join(", ", toStates)));
|
||||
transitIssueProperties.put("comment", Map.of(
|
||||
"description", "new state of the issue. Must be one of: " + String.join(", ", toStates)));
|
||||
changeIssueStateProperties.put("comment", Map.of(
|
||||
"type", "string",
|
||||
"description", "comment of the transition"));
|
||||
"description", "comment of the state change"));
|
||||
|
||||
for (var field : settingManager.getIssueSetting().getFieldSpecs()) {
|
||||
var paramName = getToolParamName(field.getName());
|
||||
|
||||
var fieldProperties = getFieldProperties(field);
|
||||
transitIssueProperties.put(paramName, fieldProperties);
|
||||
changeIssueStateProperties.put(paramName, fieldProperties);
|
||||
}
|
||||
|
||||
transitionInputSchema.put("Properties", transitIssueProperties);
|
||||
transitionInputSchema.put("Required", List.of("issueReference", "state"));
|
||||
changeIssueStateInputSchema.put("Properties", changeIssueStateProperties);
|
||||
changeIssueStateInputSchema.put("Required", List.of("issueReference", "state"));
|
||||
|
||||
inputSchemas.put("transitIssue", transitionInputSchema);
|
||||
inputSchemas.put("changeIssueState", changeIssueStateInputSchema);
|
||||
}
|
||||
|
||||
var linkSpecs = linkSpecManager.query();
|
||||
@ -1209,9 +1209,9 @@ public class McpHelperResource {
|
||||
return "Edited issue " + issueReference;
|
||||
}
|
||||
|
||||
@Path("/transit-issue")
|
||||
@Path("/change-issue-state")
|
||||
@POST
|
||||
public String transitIssue(
|
||||
public String changeIssueState(
|
||||
@QueryParam("currentProject") @NotNull String currentProjectPath,
|
||||
@QueryParam("reference") @NotNull String issueReference,
|
||||
@NotNull Map<String, Serializable> data) {
|
||||
@ -1687,13 +1687,7 @@ public class McpHelperResource {
|
||||
if (title == null)
|
||||
throw new NotAcceptableException("Title is required");
|
||||
|
||||
// Remove issue number suffix generated by AI
|
||||
var cleanedTitle = title.replaceFirst("\\s*\\([a-zA-Z]+-\\d+\\)$", "");
|
||||
cleanedTitle = cleanedTitle.replaceFirst("\\s*\\(#\\d+\\)$", "").trim();
|
||||
if (cleanedTitle.length() != 0)
|
||||
request.setTitle(cleanedTitle);
|
||||
else
|
||||
request.setTitle(title);
|
||||
request.cleanTitle();
|
||||
|
||||
request.setDescription((String) data.remove("description"));
|
||||
request.setTarget(target);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user