#1697  How to send new issue notification to project owner/admin?
Closed
Artur opened 4 months ago

For our public and open source projects we allow anybody to open a new issue. We want to make sure that an email notification will be sent to the project owner or/and admins about new issues, even if the Assignee field is empty. How can we accomplish that?

Also, I noticed you have set a default Assignee here. How can I set a default Assignee for each of our projects?

Artur commented 4 months ago

Hi, I have just found this guide: https://docs.onedev.io/tutorials/issue/default-assignee and it works as expected. So part of my question is already solved.

Now, I am still looking for a solution to get notification in case of an empty Assignee field.

Robin Shen commented 4 months ago

Just subscribe to an issue query. For instance I subscribe to all issues opened:

2023-12-22_12-30-01.png

Artur commented 4 months ago

Thank you for response. But this approach is not a good solution for us.

We have 334 projects imported from YouTrack and GitHub. We are slowly going through all of them to make sure owners/admins are set correctly and all other settings. But this takes time, especially that we have to do our normal development work.

In the meantime, community users already started their activity on the projects migrated to 1dev. They submit new issues. I would like to make sure we did not miss anything new posted to the projects, even if the project is not fully configured yet and/or an issue has an empty Assignee.

So, is there anyway, to send an email notification for any new issue to the project owner, even if the Assignee is empty?

Artur commented 4 months ago

Actually, I have just noticed I can subscribe to All issues for all projects. This is a working temp solution. But it would be better if we could send notifications to the project owner.

Robin Shen commented 4 months ago

This can be achieved with below approach:

  1. define a groovy script "watch_issues_for_project_owners":
import io.onedev.server.OneDev
import io.onedev.server.persistence.dao.Dao
import io.onedev.server.persistence.SessionManager
import io.onedev.server.model.*
	
def sessionManager = OneDev.getInstance(SessionManager.class);
sessionManager.openSession();
try {
	for (user in OneDev.getInstance(Dao.class).query(User.class)) {
		for (authorization in user.projectAuthorizations) {
			if (authorization.role.owner) {
				def personalizationOfProject = null;
				for (personalization in user.issueQueryPersonalizations) {
					if (personalization.project.equals(authorization.project)) {
						personalizationOfProject = personalization;
						break;
					}
				}
				if (personalizationOfProject == null) {
					personalizationOfProject = new IssueQueryPersonalization();
					personalizationOfProject.project = authorization.project;
					personalizationOfProject.user = user;
				}
				personalizationOfProject.queryWatchSupport.queryWatches.put("g:All", true);
				OneDev.getInstance(Dao.class).persist(personalizationOfProject);
			}
		}
	}
} finally {
	sessionManager.closeSession();
}
  1. Create a ci job in any project to call this script. This can be done by adding a command build step simply running command @script:watch_issues_for_project_owners@
Robin Shen changed state to 'Closed' 4 months ago
Previous Value Current Value
Open
Closed
issue 1 of 1
Type
Question
Priority
Normal
Assignee
Labels
No labels
Issue Votes (0)
Watchers (3)
Reference
onedev/server#1697
Please wait...
Page is in error, reload to recover