From 3a5dceae18f202cb8adf0fc49579c5460d3ce88d Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 13 Nov 2017 19:19:13 +0530 Subject: [PATCH] Add Github Connector (#11259) - Add new module ERPNext Integrations --- erpnext/erpnext_integrations/__init__.py | 0 .../connectors/__init__.py | 0 .../connectors/github_connection.py | 45 +++++++++++++++++++ .../data_migration_mapping/__init__.py | 0 .../issue_to_task/__init__.py | 11 +++++ .../issue_to_task/issue_to_task.json | 36 +++++++++++++++ .../milestone_to_project/__init__.py | 6 +++ .../milestone_to_project.json | 36 +++++++++++++++ .../github_sync/github_sync.json | 22 +++++++++ erpnext/modules.txt | 1 + 10 files changed, 157 insertions(+) create mode 100644 erpnext/erpnext_integrations/__init__.py create mode 100644 erpnext/erpnext_integrations/connectors/__init__.py create mode 100644 erpnext/erpnext_integrations/connectors/github_connection.py create mode 100644 erpnext/erpnext_integrations/data_migration_mapping/__init__.py create mode 100644 erpnext/erpnext_integrations/data_migration_mapping/issue_to_task/__init__.py create mode 100644 erpnext/erpnext_integrations/data_migration_mapping/issue_to_task/issue_to_task.json create mode 100644 erpnext/erpnext_integrations/data_migration_mapping/milestone_to_project/__init__.py create mode 100644 erpnext/erpnext_integrations/data_migration_mapping/milestone_to_project/milestone_to_project.json create mode 100644 erpnext/erpnext_integrations/data_migration_plan/github_sync/github_sync.json diff --git a/erpnext/erpnext_integrations/__init__.py b/erpnext/erpnext_integrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/erpnext_integrations/connectors/__init__.py b/erpnext/erpnext_integrations/connectors/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/erpnext_integrations/connectors/github_connection.py b/erpnext/erpnext_integrations/connectors/github_connection.py new file mode 100644 index 0000000000..ab7708df30 --- /dev/null +++ b/erpnext/erpnext_integrations/connectors/github_connection.py @@ -0,0 +1,45 @@ +from __future__ import unicode_literals +import frappe +from frappe.data_migration.doctype.data_migration_connector.connectors.base import BaseConnection +from github import Github + +class GithubConnection(BaseConnection): + def __init__(self, connector): + self.connector = connector + + try: + password = self.get_password() + except frappe.AuthenticationError: + password = None + + if self.connector.username and password: + self.connection = Github(self.connector.username, self.get_password()) + else: + self.connection = Github() + + self.name_field = 'id' + + def insert(self, doctype, doc): + pass + + def update(self, doctype, doc, migration_id): + pass + + def delete(self, doctype, migration_id): + pass + + def get(self, remote_objectname, fields=None, filters=None, start=0, page_length=10): + repo = filters.get('repo') + + if remote_objectname == 'Milestone': + return self.get_milestones(repo, start, page_length) + if remote_objectname == 'Issue': + return self.get_issues(repo, start, page_length) + + def get_milestones(self, repo, start=0, page_length=10): + _repo = self.connection.get_repo(repo) + return list(_repo.get_milestones()[start:start+page_length]) + + def get_issues(self, repo, start=0, page_length=10): + _repo = self.connection.get_repo(repo) + return list(_repo.get_issues()[start:start+page_length]) diff --git a/erpnext/erpnext_integrations/data_migration_mapping/__init__.py b/erpnext/erpnext_integrations/data_migration_mapping/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/erpnext_integrations/data_migration_mapping/issue_to_task/__init__.py b/erpnext/erpnext_integrations/data_migration_mapping/issue_to_task/__init__.py new file mode 100644 index 0000000000..5f0f691b9c --- /dev/null +++ b/erpnext/erpnext_integrations/data_migration_mapping/issue_to_task/__init__.py @@ -0,0 +1,11 @@ +import frappe + +def pre_process(issue): + + project = frappe.db.get_value('Project', filters={'project_name': issue.milestone}) + return { + 'title': issue.title, + 'body': frappe.utils.to_html(issue.body or ''), + 'state': issue.state.title(), + 'project': project or '' + } diff --git a/erpnext/erpnext_integrations/data_migration_mapping/issue_to_task/issue_to_task.json b/erpnext/erpnext_integrations/data_migration_mapping/issue_to_task/issue_to_task.json new file mode 100644 index 0000000000..e945ba2261 --- /dev/null +++ b/erpnext/erpnext_integrations/data_migration_mapping/issue_to_task/issue_to_task.json @@ -0,0 +1,36 @@ +{ + "condition": "{\"repo\":\"frappe/erpnext\"}", + "creation": "2017-10-16 16:03:32.772191", + "docstatus": 0, + "doctype": "Data Migration Mapping", + "fields": [ + { + "is_child_table": 0, + "local_fieldname": "subject", + "remote_fieldname": "title" + }, + { + "is_child_table": 0, + "local_fieldname": "description", + "remote_fieldname": "body" + }, + { + "is_child_table": 0, + "local_fieldname": "status", + "remote_fieldname": "state" + } + ], + "idx": 0, + "local_doctype": "Task", + "local_primary_key": "name", + "mapping_name": "Issue to Task", + "mapping_type": "Pull", + "migration_id_field": "github_sync_id", + "modified": "2017-10-20 11:48:54.575993", + "modified_by": "Administrator", + "name": "Issue to Task", + "owner": "Administrator", + "page_length": 10, + "remote_objectname": "Issue", + "remote_primary_key": "id" +} \ No newline at end of file diff --git a/erpnext/erpnext_integrations/data_migration_mapping/milestone_to_project/__init__.py b/erpnext/erpnext_integrations/data_migration_mapping/milestone_to_project/__init__.py new file mode 100644 index 0000000000..212f81b5f9 --- /dev/null +++ b/erpnext/erpnext_integrations/data_migration_mapping/milestone_to_project/__init__.py @@ -0,0 +1,6 @@ +def pre_process(milestone): + return { + 'title': milestone.title, + 'description': milestone.description, + 'state': milestone.state.title() + } diff --git a/erpnext/erpnext_integrations/data_migration_mapping/milestone_to_project/milestone_to_project.json b/erpnext/erpnext_integrations/data_migration_mapping/milestone_to_project/milestone_to_project.json new file mode 100644 index 0000000000..5a3e07e37e --- /dev/null +++ b/erpnext/erpnext_integrations/data_migration_mapping/milestone_to_project/milestone_to_project.json @@ -0,0 +1,36 @@ +{ + "condition": "{\"repo\": \"frappe/erpnext\"}", + "creation": "2017-10-13 11:16:49.664925", + "docstatus": 0, + "doctype": "Data Migration Mapping", + "fields": [ + { + "is_child_table": 0, + "local_fieldname": "project_name", + "remote_fieldname": "title" + }, + { + "is_child_table": 0, + "local_fieldname": "notes", + "remote_fieldname": "description" + }, + { + "is_child_table": 0, + "local_fieldname": "status", + "remote_fieldname": "state" + } + ], + "idx": 0, + "local_doctype": "Project", + "local_primary_key": "project_name", + "mapping_name": "Milestone to Project", + "mapping_type": "Pull", + "migration_id_field": "github_sync_id", + "modified": "2017-10-20 11:48:54.552305", + "modified_by": "Administrator", + "name": "Milestone to Project", + "owner": "Administrator", + "page_length": 10, + "remote_objectname": "Milestone", + "remote_primary_key": "id" +} \ No newline at end of file diff --git a/erpnext/erpnext_integrations/data_migration_plan/github_sync/github_sync.json b/erpnext/erpnext_integrations/data_migration_plan/github_sync/github_sync.json new file mode 100644 index 0000000000..20eb387cd8 --- /dev/null +++ b/erpnext/erpnext_integrations/data_migration_plan/github_sync/github_sync.json @@ -0,0 +1,22 @@ +{ + "creation": "2017-10-13 11:16:53.600026", + "docstatus": 0, + "doctype": "Data Migration Plan", + "idx": 0, + "mappings": [ + { + "enabled": 1, + "mapping": "Milestone to Project" + }, + { + "enabled": 1, + "mapping": "Issue to Task" + } + ], + "modified": "2017-10-20 11:48:54.496123", + "modified_by": "Administrator", + "module": "ERPNext Integrations", + "name": "GitHub Sync", + "owner": "Administrator", + "plan_name": "GitHub Sync" +} \ No newline at end of file diff --git a/erpnext/modules.txt b/erpnext/modules.txt index 5e9f6c73d1..79ded14573 100644 --- a/erpnext/modules.txt +++ b/erpnext/modules.txt @@ -17,3 +17,4 @@ Schools Regional Healthcare Restaurant +ERPNext Integrations \ No newline at end of file