Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions erpnext_github_integration/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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")
Expand Down
18 changes: 13 additions & 5 deletions erpnext_github_integration/public/js/task_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -17,24 +21,28 @@ 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;
if (!repo) {
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},
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -148,6 +156,6 @@ frappe.ui.form.on('Task', {
});
}, __('Assign PR Reviewer'));
});
});
}, __('GitHub'));
}
});
Loading