Question about Groovy Script Integration #2873
Zak Siddiqui opened 2 weeks ago

@robin refencing https://code.onedev.io/onedev/server/~issues/2872#IssueComment-10051

Then configure assignee field of the issue to evaluate this script to get the default value.

I'm trying to understand how the returned value gets assigned to the assignee field. What value do we put in the assignee field to evaluate the script?

I write a small groovy script to assign all minor issues and questions to work horse automatically:

import io.onedev.server.util.EditContext

def type = EditContext.get().getInputValue("Type")
def priority = EditContext.get().getInputValue("Priority");

if (type == "Question" || type == "Bug" || priority == "Minor")
	return "wh"
else
	return "robin"

Then configure assignee field of the issue to evaluate this script to get the default value. Then in system prompt of work horse tell it to escalate the issues to me in certain cases:

When you are assigned with an issue of type "Question", try to answer user the question without creating branch or change code. If user is fine with the answer, close the issue then; otherwise, escalate to @robin. Project "onedev/docs" may also be useful when answer questions.

Here is a screenshot of my groovy implementation.

image.png

  • Work Horse commented 2 weeks ago

    You do not put a special value into the Assignee field when creating an issue. The Groovy script is wired through the Assignee field definition, not as a value typed into the field itself.

    How to connect your script

    1. Go to Administration โ†’ Issue Setting โ†’ Custom Fields (or the project's issue field settings if they override the global ones).
    2. Edit the Assignee / Assignees field.
    3. Set Default Value to Evaluate script to get default value.
    4. Select your script by its Name โ€” from your screenshot that is Assign Questions to Junior Mechanic.

    After that, when someone opens the new-issue form, OneDev evaluates the script and uses the return value as the default assignee. The script should return a user login name (juniormechanic in your example). If the field allows multiple values, return a string or a list of login names.

    Docs:

    Notes on your script

    • The Can Be Used By Jobs / Workspace Specs toggles only restrict CI/workspace use. They are not required for issue field default values.
    • Without an else branch, Type/Priority combinations that do not match return null and leave Assignee empty (Robinโ€™s example returns another login in that case). Add an else if you want a fallback assignee.

    If this clears things up, we can close the issue; otherwise say what is still unclear and we can escalate to @robin.

  • Zak Siddiqui commented 2 weeks ago

    Amazing

  • Zak Siddiqui commented 2 weeks ago

    Answered by wh

  • Zak Siddiqui changed state to 'Closed' 2 weeks ago
    Previous Value Current Value
    Open
    Closed
1/1
Type
Question
Priority
Normal
Assignee
Labels
No labels
Issue Votes (0)
Watchers (4)
Reference
OD-2873
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover