diff --git a/erpnext_github_integration/github_api.py b/erpnext_github_integration/github_api.py index e80e10e..b7bdc5f 100644 --- a/erpnext_github_integration/github_api.py +++ b/erpnext_github_integration/github_api.py @@ -302,6 +302,8 @@ def assign_issue(repo_full_name, issue_number, assignees): # Clear existing assignments clear("Repository Issue", local.name) if task: + task_doc = frappe.get_doc('Task', task.name) + task_doc.set('assigned_to_users', []) clear("Task", task.name) for user_id in assignees: @@ -322,6 +324,10 @@ def assign_issue(repo_full_name, issue_number, assignees): 'issue': local.name, 'user': user_id }) + if task: + task_doc.append('assigned_to_users', { + 'user': user_id + }) # also create ERPNext assignments try: @@ -342,6 +348,7 @@ def assign_issue(repo_full_name, issue_number, assignees): frappe.log_error(frappe.get_traceback(), "Failed to create Frappe assignment") local.save(ignore_permissions=True) + task_doc.save(ignore_permissions=True) if task else None except Exception: frappe.log_error(frappe.get_traceback(), "Failed to update local Repository Issue assignees") diff --git a/erpnext_github_integration/public/js/task_client.js b/erpnext_github_integration/public/js/task_client.js index c310969..afeba4d 100644 --- a/erpnext_github_integration/public/js/task_client.js +++ b/erpnext_github_integration/public/js/task_client.js @@ -6,6 +6,10 @@ frappe.ui.form.on('Task', { frappe.msgprint(__('Please set the GitHub Repo (link to Repository) in the Task field "GitHub Repo"')); return; } + if (frm.doc.github_issue_number) { + frappe.msgprint(__('This Task already has a linked GitHub Issue (#' + frm.doc.github_issue_number + ')')); + return; + } frappe.prompt([ {'fieldname':'title','fieldtype':'Data','label':'Issue Title','reqd':1}, @@ -17,17 +21,17 @@ frappe.ui.form.on('Task', { callback: function(r) { if (r.message) { let issue = r.message.issue; - frappe.msgprint(__('Issue Successfully Created')); // Save both: local doc link & GitHub issue number frm.set_value('github_issue_doc', r.message.local_doc); frm.set_value('github_issue_number', issue.number); frm.save(); + frappe.msgprint(__('Github Issue Successfully Created')); } } }); }, __('Create GitHub Issue')); - }); + }, __('GitHub')); frm.add_custom_button(__('Create Pull Request'), function() { let repo = frm.doc.github_repo; @@ -35,6 +39,10 @@ frappe.ui.form.on('Task', { frappe.msgprint(__('Please set the GitHub Repo (link to Repository) in the Task field "GitHub Repo"')); return; } + if (frm.doc.github_pr_number) { + frappe.msgprint(__('This Task already has a linked GitHub Pull Request (#' + frm.doc.github_pr_number + ')')); + return; + } frappe.prompt([ {'fieldname':'title','fieldtype':'Data','label':'PR Title','reqd':1}, {'fieldname':'head','fieldtype':'Data','label':'Head Branch (feature-branch)','reqd':1}, @@ -54,7 +62,7 @@ frappe.ui.form.on('Task', { } }); }, __('Create Pull Request')); - }); + }, __('GitHub')); frm.add_custom_button(__('Assign Issue'), function() { let repo = frm.doc.github_repo; @@ -98,7 +106,7 @@ frappe.ui.form.on('Task', { }); }, __('Assign Issue')); }); - }); + }, __('GitHub')); frm.add_custom_button(__('Assign PR Reviewer'), function() { let repo = frm.doc.github_repo; @@ -148,6 +156,6 @@ frappe.ui.form.on('Task', { }); }, __('Assign PR Reviewer')); }); - }); + }, __('GitHub')); } });