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
23 changes: 14 additions & 9 deletions erpnext_github_integration/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ def validate_repository(doc, method):
def get_repository_dashboard_data(data):
"""Get dashboard data for Repository doctype"""
return {
"heatmap": True,
"heatmap_message": _("This is based on the commits in the repository"),
"fieldname": "repository", # This is the default fieldname
"fieldname": "repository", # main link field for connections
"non_standard_fieldnames": {
"Task": "github_repo"
},
"transactions": [
{
"label": _("Issues & PRs"),
"items": ["Repository Issue", "Repository Pull Request"]
},
{
"label": _("Project Management"),
"items": [
{"item": "Project", "fieldname": "repository"}, # Project uses 'repository' field
{"item": "Task", "fieldname": "github_repo"} # Task uses 'github_repo' field
]
"items": ["Project", "Task"]
}
]
}
Expand Down Expand Up @@ -310,9 +308,16 @@ def link_github_user_to_erp(github_username, erp_user):
user_doc = frappe.get_doc('User', erp_user)
user_doc.github_username = github_username
user_doc.save(ignore_permissions=True)
return {'success': True, 'message': _('GitHub username linked successfully')}
except Exception as e:
return {
'success': True,
'message': _('GitHub username {0} linked successfully to user {1}').format(
github_username, erp_user)
}
except frappe.ValidationError as e:
return {'success': False, 'error': str(e)}
except Exception as e:
frappe.log_error(f'Error linking GitHub user: {str(e)}')
return {'success': False, 'error': _('An error occurred while updating the user')}

@frappe.whitelist()
def get_repository_statistics(repo_full_name):
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"column_break_nwhs",
"default_organization",
"default_visibility",
"sync_interval_minutes",
"rate_limit_threshold",
"last_sync",
"enabled"
],
Expand Down Expand Up @@ -59,16 +57,6 @@
"label": "Default Visibility",
"options": "Public\nPrivate"
},
{
"fieldname": "sync_interval_minutes",
"fieldtype": "Int",
"label": "Sync Interval Minutes"
},
{
"fieldname": "rate_limit_threshold",
"fieldtype": "Int",
"label": "Rate Limit Threshold"
},
{
"fieldname": "last_sync",
"fieldtype": "Datetime",
Expand All @@ -83,7 +71,7 @@
],
"issingle": 1,
"links": [],
"modified": "2025-08-20 11:42:40.710361",
"modified": "2025-08-21 14:54:53.501895",
"modified_by": "Administrator",
"module": "Erpnext Github Integration",
"name": "GitHub Settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,34 +149,60 @@ frappe.ui.form.on("Repository", {
frm.add_custom_button(__('Show Activity'), function() {
frappe.call({
method: 'erpnext_github_integration.github_api.get_repository_activity',
args: {repo_full_name: frm.doc.full_name, days: 30},
args: {repository: frm.doc.full_name, days: 30},
callback: function(r) {
if (r.message) {
if (r.message && !r.message.error) {
let activity = r.message;
let html = '<div style="max-height: 400px; overflow-y: auto;">';

if (activity.commits && activity.commits.length) {
// Summary statistics
html += `<div class="alert alert-info">
<strong>Activity Summary (Last ${activity.period_days} days):</strong><br>
Commits: ${activity.commits} | Issues: ${activity.issues} | Pull Requests: ${activity.pulls}
</div>`;

// Recent commits
if (activity.details && activity.details.commits && activity.details.commits.length) {
html += '<h5>Recent Commits</h5><ul>';
activity.commits.slice(0, 10).forEach(commit => {
html += `<li><strong>${commit.commit.message.split('\n')[0]}</strong><br>
<small>by ${commit.commit.author.name} on ${frappe.datetime.str_to_user(commit.commit.author.date)}</small></li>`;
activity.details.commits.forEach(commit => {
const message = commit.commit ? commit.commit.message : commit.message;
const author = commit.commit && commit.commit.author ? commit.commit.author.name :
commit.author ? commit.author.login : 'Unknown';
const date = commit.commit && commit.commit.author ? commit.commit.author.date :
commit.commit ? commit.commit.committer.date : '';

html += `<li><strong>${(message || '').split('\n')[0]}</strong><br>
<small>by ${author} on ${date ? frappe.datetime.str_to_user(date) : 'unknown date'}</small></li>`;
});
html += '</ul>';
} else {
html += '<p>No recent commits</p>';
}

// Recent issues
if (activity.details && activity.details.issues && activity.details.issues.length) {
html += '<h5>Recent Issues</h5><ul>';
activity.details.issues.forEach(issue => {
html += `<li><strong>#${issue.number}: ${issue.title}</strong> - ${issue.state}<br>
<small>by ${issue.user ? issue.user.login : 'Unknown'} on ${frappe.datetime.str_to_user(issue.created_at)}</small></li>`;
});
html += '</ul>';
}

if (activity.events && activity.events.length) {
html += '<h5>Recent Events</h5><ul>';
activity.events.slice(0, 10).forEach(event => {
html += `<li><strong>${event.type}</strong> by ${event.actor.login}<br>
<small>${frappe.datetime.str_to_user(event.created_at)}</small></li>`;
// Recent pull requests
if (activity.details && activity.details.pulls && activity.details.pulls.length) {
html += '<h5>Recent Pull Requests</h5><ul>';
activity.details.pulls.forEach(pr => {
html += `<li><strong>#${pr.number}: ${pr.title}</strong> - ${pr.state}<br>
<small>by ${pr.user ? pr.user.login : 'Unknown'} on ${frappe.datetime.str_to_user(pr.created_at)}</small></li>`;
});
html += '</ul>';
}

html += '</div>';

let d = new frappe.ui.Dialog({
title: __('Repository Activity (Last 30 days)'),
title: __('Repository Activity (Last {0} days)', [activity.period_days]),
fields: [{
fieldname: 'activity',
fieldtype: 'HTML',
Expand All @@ -185,6 +211,8 @@ frappe.ui.form.on("Repository", {
size: 'large'
});
d.show();
} else {
frappe.msgprint(__('Failed to load activity: {0}', [r.message ? r.message.error : 'Unknown error']));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"project",
"is_synced",
"last_synced",
"enabled",
"column_break_dsmh",
"repo_name",
"repo_owner",
Expand Down Expand Up @@ -103,10 +104,16 @@
"fieldname": "member_section",
"fieldtype": "Section Break",
"label": "Member"
},
{
"default": "1",
"fieldname": "enabled",
"fieldtype": "Check",
"label": "Enabled"
}
],
"links": [],
"modified": "2025-08-20 15:52:23.049815",
"modified": "2025-08-21 11:56:17.540867",
"modified_by": "Administrator",
"module": "Erpnext Github Integration",
"name": "Repository",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"actions": [],
"autoname": "field:title",
"autoname": "format:{repository}-#{issue_number}",
"creation": "2025-08-12 18:03:45.384921",
"doctype": "DocType",
"engine": "InnoDB",
Expand Down Expand Up @@ -31,15 +31,16 @@
{
"fieldname": "issue_number",
"fieldtype": "Int",
"in_filter": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Issue Number",
"reqd": 1
},
{
"fieldname": "title",
"fieldtype": "Data",
"label": "Title",
"unique": 1
"label": "Title"
},
{
"fieldname": "body",
Expand Down Expand Up @@ -94,11 +95,11 @@
}
],
"links": [],
"modified": "2025-08-20 15:55:01.486955",
"modified": "2025-08-21 14:06:23.824247",
"modified_by": "Administrator",
"module": "Erpnext Github Integration",
"name": "Repository Issue",
"naming_rule": "By fieldname",
"naming_rule": "Expression",
"owner": "Administrator",
"permissions": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"actions": [],
"autoname": "field:title",
"autoname": "format:{repository}-#{pr_number}",
"creation": "2025-08-12 18:03:44.866127",
"doctype": "DocType",
"engine": "InnoDB",
Expand All @@ -26,8 +26,8 @@
{
"fieldname": "title",
"fieldtype": "Data",
"label": "Title",
"unique": 1
"in_list_view": 1,
"label": "Title"
},
{
"fieldname": "repository",
Expand All @@ -40,7 +40,9 @@
{
"fieldname": "pr_number",
"fieldtype": "Int",
"in_filter": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "PR Number",
"reqd": 1
},
Expand Down Expand Up @@ -112,11 +114,11 @@
}
],
"links": [],
"modified": "2025-08-20 15:54:43.666661",
"modified": "2025-08-21 14:46:22.038600",
"modified_by": "Administrator",
"module": "Erpnext Github Integration",
"name": "Repository Pull Request",
"naming_rule": "By fieldname",
"naming_rule": "Expression",
"owner": "Administrator",
"permissions": [
{
Expand Down
Loading
Loading