From 1c95ddfa09ec0aa1f07ee9ad50a77be1dd74b55e Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Tue, 13 Mar 2012 20:11:37 +0100 Subject: [PATCH] Spliting GithubObjects.py --- github/GithubObjects.py | 108 ++--------------------------------- github/Issue.py | 39 +++++++++++++ github/Milestone.py | 22 +++++++ github/PullRequest.py | 42 ++++++++++++++ github/PullRequestComment.py | 16 ++++++ github/PullRequestFile.py | 9 +++ 6 files changed, 134 insertions(+), 102 deletions(-) create mode 100644 github/Issue.py create mode 100644 github/Milestone.py create mode 100644 github/PullRequest.py create mode 100644 github/PullRequestComment.py create mode 100644 github/PullRequestFile.py diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 98b02707..539e4a9f 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -22,117 +22,21 @@ from GitCommit import GitCommit from GitBlob import GitBlob from GitTag import GitTag from Label import Label - -__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } - -Milestone = GithubObject( - "Milestone", - BaseUrl( lambda obj: obj._repo._baseUrl() + "/milestones/" + str( obj.number ) ), - InternalSimpleAttributes( - "url", "number", "state", "title", "description", "open_issues", - "closed_issues", "created_at", "due_on", - "_repo", - ), - InternalObjectAttribute( "creator", NamedUser ), - Editable( [ "title" ], [ "state", "description", "due_on" ] ), - Deletable(), - ExternalListOfObjects( "labels", "label", Label, - ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ) - ), -) - +from Milestone import Milestone from IssueComment import IssueComment from IssueEvent import IssueEvent - -Issue = GithubObject( - "Issue", - BaseUrl( lambda obj: obj._repo._baseUrl() + "/issues/" + str( obj.number ) ), - InternalSimpleAttributes( - "url", "html_url", "number", "state", "title", "body", "labels", - "comments", "closed_at", "created_at", "updated_at", "id", "closed_by", - "pull_request", - "_repo", - ), - InternalObjectAttribute( "user", NamedUser ), - InternalObjectAttribute( "assignee", NamedUser ), - InternalObjectAttribute( "milestone", Milestone ), - Editable( [], [ "title", "body", "assignee", "state", "milestone", "labels" ] ), - ExternalListOfObjects( "labels", "label", Label, - ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), - SeveralElementsAddable(), - ListSetable(), - ListDeletable(), - ElementRemovable(), - ), - ExternalListOfObjects( "comments", "comment", IssueComment, - ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), - ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingReferedRepo ), - ElementCreatable( [ "body" ], [], __modifyAttributesForObjectsReferingReferedRepo ), - ), - ExternalListOfObjects( "events", "event", IssueEvent, - ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ) - ), -) - +from Issue import Issue from Download import Download from CommitComment import CommitComment from Commit import Commit from Tag import Tag from Branch import Branch +from PullRequestFile import PullRequestFile +from PullRequestComment import PullRequestComment +from PullRequest import PullRequest +__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } __modifyAttributesForObjectsReferingRepo = { "_repo": lambda repo: repo } -PullRequestFile = GithubObject( - "PullRequestFile", - InternalSimpleAttributes( - "sha", "filename", "status", "additions", "deletions", "changes", - "blob_url", "raw_url", "patch", - ), -) - -PullRequestComment = GithubObject( - "PullRequestComment", - BaseUrl( lambda obj: obj._repo._baseUrl() + "/pulls/comments/" + str( obj.id ) ), - InternalSimpleAttributes( - "url", "id", "body", "path", "position", "commit_id", - "created_at", "updated_at", "html_url", "line", - "_repo", - ), - InternalObjectAttribute( "user", NamedUser ), - Editable( [ "body" ], [] ), - Deletable(), -) - -def __pullRequestIsMerged( r ): - return r._github._statusRequest( "GET", r._baseUrl() + "/merge", None, None ) == 204 -def __mergePullRequest( r, **data ): - r._github._statusRequest( "PUT", r._baseUrl() + "/merge", None, data ) -PullRequest = GithubObject( - "PullRequest", - BaseUrl( lambda obj: obj._repo._baseUrl() + "/pulls/" + str( obj.number ) ), - InternalSimpleAttributes( - "id", "url", "html_url", "diff_url", "patch_url", "issue_url", "number", - "state", "title", "body", "created_at", "updated_at", "closed_at", - "merged_at", "_links", "merged", "mergeable", "comments", "commits", - "additions", "deletions", "changed_files", "head", "base", "merged_by", - "review_comments", - "_repo", - ), - InternalObjectAttribute( "user", NamedUser ), - Editable( [], [ "title", "body", "state" ] ), - ExternalListOfObjects( "commits", "commit", Commit, - ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), - ), - ExternalListOfObjects( "files", "file", PullRequestFile, - ListGetable( [], [] ), - ), - ExternalListOfObjects( "comments", "comment", PullRequestComment, - ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), - ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingReferedRepo ), - ElementCreatable( [ "body", "commit_id", "path", "position" ], [], __modifyAttributesForObjectsReferingReferedRepo ), - ), - MethodFromCallable( "is_merged", [], [], __pullRequestIsMerged, SimpleTypePolicy( "bool" ) ), - MethodFromCallable( "merge", [], [ "commit_message" ], __mergePullRequest, SimpleTypePolicy( None ) ), -) RepositoryKey = GithubObject( "RepositoryKey", diff --git a/github/Issue.py b/github/Issue.py new file mode 100644 index 00000000..f03e69bf --- /dev/null +++ b/github/Issue.py @@ -0,0 +1,39 @@ +from GithubObject import * + +from NamedUser import NamedUser +from Milestone import Milestone +from Label import Label +from IssueComment import IssueComment +from IssueEvent import IssueEvent + +__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } + +Issue = GithubObject( + "Issue", + BaseUrl( lambda obj: obj._repo._baseUrl() + "/issues/" + str( obj.number ) ), + InternalSimpleAttributes( + "url", "html_url", "number", "state", "title", "body", "labels", + "comments", "closed_at", "created_at", "updated_at", "id", "closed_by", + "pull_request", + "_repo", + ), + InternalObjectAttribute( "user", NamedUser ), + InternalObjectAttribute( "assignee", NamedUser ), + InternalObjectAttribute( "milestone", Milestone ), + Editable( [], [ "title", "body", "assignee", "state", "milestone", "labels" ] ), + ExternalListOfObjects( "labels", "label", Label, + ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), + SeveralElementsAddable(), + ListSetable(), + ListDeletable(), + ElementRemovable(), + ), + ExternalListOfObjects( "comments", "comment", IssueComment, + ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), + ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingReferedRepo ), + ElementCreatable( [ "body" ], [], __modifyAttributesForObjectsReferingReferedRepo ), + ), + ExternalListOfObjects( "events", "event", IssueEvent, + ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ) + ), +) diff --git a/github/Milestone.py b/github/Milestone.py new file mode 100644 index 00000000..a2531c93 --- /dev/null +++ b/github/Milestone.py @@ -0,0 +1,22 @@ +from GithubObject import * + +from NamedUser import NamedUser +from Label import Label + +__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } + +Milestone = GithubObject( + "Milestone", + BaseUrl( lambda obj: obj._repo._baseUrl() + "/milestones/" + str( obj.number ) ), + InternalSimpleAttributes( + "url", "number", "state", "title", "description", "open_issues", + "closed_issues", "created_at", "due_on", + "_repo", + ), + InternalObjectAttribute( "creator", NamedUser ), + Editable( [ "title" ], [ "state", "description", "due_on" ] ), + Deletable(), + ExternalListOfObjects( "labels", "label", Label, + ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ) + ), +) diff --git a/github/PullRequest.py b/github/PullRequest.py new file mode 100644 index 00000000..a8947a62 --- /dev/null +++ b/github/PullRequest.py @@ -0,0 +1,42 @@ +from GithubObject import * + +from NamedUser import NamedUser +from Commit import Commit +from PullRequestFile import PullRequestFile +from PullRequestComment import PullRequestComment + +__modifyAttributesForObjectsReferingReferedRepo = { "_repo": lambda obj: obj._repo } + +def __pullRequestIsMerged( r ): + return r._github._statusRequest( "GET", r._baseUrl() + "/merge", None, None ) == 204 + +def __mergePullRequest( r, **data ): + r._github._statusRequest( "PUT", r._baseUrl() + "/merge", None, data ) + +PullRequest = GithubObject( + "PullRequest", + BaseUrl( lambda obj: obj._repo._baseUrl() + "/pulls/" + str( obj.number ) ), + InternalSimpleAttributes( + "id", "url", "html_url", "diff_url", "patch_url", "issue_url", "number", + "state", "title", "body", "created_at", "updated_at", "closed_at", + "merged_at", "_links", "merged", "mergeable", "comments", "commits", + "additions", "deletions", "changed_files", "head", "base", "merged_by", + "review_comments", + "_repo", + ), + InternalObjectAttribute( "user", NamedUser ), + Editable( [], [ "title", "body", "state" ] ), + ExternalListOfObjects( "commits", "commit", Commit, + ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), + ), + ExternalListOfObjects( "files", "file", PullRequestFile, + ListGetable( [], [] ), + ), + ExternalListOfObjects( "comments", "comment", PullRequestComment, + ListGetable( [], [], __modifyAttributesForObjectsReferingReferedRepo ), + ElementGetable( [ "id" ], [], __modifyAttributesForObjectsReferingReferedRepo ), + ElementCreatable( [ "body", "commit_id", "path", "position" ], [], __modifyAttributesForObjectsReferingReferedRepo ), + ), + MethodFromCallable( "is_merged", [], [], __pullRequestIsMerged, SimpleTypePolicy( "bool" ) ), + MethodFromCallable( "merge", [], [ "commit_message" ], __mergePullRequest, SimpleTypePolicy( None ) ), +) diff --git a/github/PullRequestComment.py b/github/PullRequestComment.py new file mode 100644 index 00000000..2985d92d --- /dev/null +++ b/github/PullRequestComment.py @@ -0,0 +1,16 @@ +from GithubObject import * + +from NamedUser import NamedUser + +PullRequestComment = GithubObject( + "PullRequestComment", + BaseUrl( lambda obj: obj._repo._baseUrl() + "/pulls/comments/" + str( obj.id ) ), + InternalSimpleAttributes( + "url", "id", "body", "path", "position", "commit_id", + "created_at", "updated_at", "html_url", "line", + "_repo", + ), + InternalObjectAttribute( "user", NamedUser ), + Editable( [ "body" ], [] ), + Deletable(), +) diff --git a/github/PullRequestFile.py b/github/PullRequestFile.py new file mode 100644 index 00000000..d7135d16 --- /dev/null +++ b/github/PullRequestFile.py @@ -0,0 +1,9 @@ +from GithubObject import * + +PullRequestFile = GithubObject( + "PullRequestFile", + InternalSimpleAttributes( + "sha", "filename", "status", "additions", "deletions", "changes", + "blob_url", "raw_url", "patch", + ), +)