mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Initial solution for [PyGithub support for projects](https://github.com/PyGithub/PyGithub/issues/606) (#606). Adds comprehensive project querying API. Currently does not support for modifying projects, columns or cards. (I only need this interface for reporting purposes. Of course once I'm done others are more than welcome to add additional features!) API that was integrated: https://developer.github.com/v3/projects https://developer.github.com/v3/projects/columns https://developer.github.com/v3/projects/cards Note that the Github project API is in preview mode - it requires a special header in order for requests to be processed, and the API is subject to change without notice. ## Summary - new classes: Project, ProjectColumn, ProjectCard - add Organization.get_projects method - add Repository.get_projects method - add MainClass.get_project method - add test cases to exercise all new classes and methods and verify attributes are as expected; replay data is included, recorded (mostly) from my fork of PyGithub - updated add_attribute script to: - use makeXXXAttribute API - be able to add to the end of the current set of properties - handle both Completable and NonCompletable class types correctly ## Checklist Not to be merged until these are done: - [x] remaining Project properties - [x] remaining ProjectColumn properties - [x] remaining ProjectCard properties - [x] support for archived_state parameter when getting cards: all,archived, or not_archived - [x] get issue from card, not just pull request ("get_content" method?) - [x] centralize header management for "preview" access to projects API - [x] add test for retrieving organization projects - [x] add test for getting issue / pull request content from card
132 lines
6.5 KiB
Python
132 lines
6.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# ########################## Copyrights and license ############################
|
|
# #
|
|
# Copyright 2018 bbi-yggy <yossarian@blackbirdinteractive.com> #
|
|
# #
|
|
# This file is part of PyGithub. #
|
|
# http://pygithub.github.io/PyGithub/v1/index.html #
|
|
# #
|
|
# PyGithub is free software: you can redistribute it and/or modify it under #
|
|
# the terms of the GNU Lesser General Public License as published by the Free #
|
|
# Software Foundation, either version 3 of the License, or (at your option) #
|
|
# any later version. #
|
|
# #
|
|
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
|
|
# details. #
|
|
# #
|
|
# You should have received a copy of the GNU Lesser General Public License #
|
|
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
|
# #
|
|
# ##############################################################################
|
|
|
|
import Framework
|
|
import github
|
|
|
|
class Project(Framework.TestCase):
|
|
def setUp(self):
|
|
Framework.TestCase.setUp(self)
|
|
self.repo = self.g.get_user().get_repo('PyGithub')
|
|
|
|
def testGetProject(self):
|
|
id = 1682941
|
|
proj = self.g.get_project(id)
|
|
self.assertEqual(proj.id, id)
|
|
self.assertEqual(proj.name, 'TestProject')
|
|
|
|
def testGetOrganizationProjects(self):
|
|
expectedProjects = ['Project1', 'Project2', 'Project3']
|
|
org = self.g.get_organization('PyGithubTestOrg')
|
|
projects = []
|
|
for proj in org.get_projects("open"):
|
|
projects.append(proj.name)
|
|
self.assertEqual(projects, expectedProjects)
|
|
|
|
def testGetRepositoryProjects(self):
|
|
expectedProjects = ['TestProject', 'TestProjectClosed']
|
|
projects = []
|
|
for proj in self.repo.get_projects("all"):
|
|
projects.append(proj.name)
|
|
self.assertEqual(projects, expectedProjects)
|
|
|
|
# See https://developer.github.com/v3/projects/#get-a-project
|
|
def testProjectAttributes(self):
|
|
id = 1682941
|
|
proj = self.g.get_project(id)
|
|
self.assertEqual(proj.owner_url, "https://api.github.com/repos/bbi-yggy/PyGithub")
|
|
self.assertEqual(proj.url, "https://api.github.com/projects/1682941")
|
|
self.assertEqual(proj.html_url, "https://github.com/bbi-yggy/PyGithub/projects/1")
|
|
self.assertEqual(proj.columns_url, "https://api.github.com/projects/1682941/columns")
|
|
self.assertEqual(proj.id, id)
|
|
self.assertEqual(proj.node_id, "MDc6UHJvamVjdDE2ODI5NDE=")
|
|
self.assertEqual(proj.name, 'TestProject')
|
|
self.assertEqual(proj.body, "To be used for testing project access API for PyGithub.")
|
|
self.assertEqual(proj.number, 1)
|
|
self.assertEqual(proj.state, "open")
|
|
self.assertEqual(proj.creator, self.repo.owner)
|
|
self.assertEqual(proj.created_at.year, 2018)
|
|
self.assertTrue(proj.updated_at > proj.created_at)
|
|
|
|
# See https://developer.github.com/v3/projects/columns/#get-a-project-column
|
|
def testProjectColumnAttributes(self):
|
|
proj = self.g.get_project(1682941)
|
|
col = proj.get_columns()[0]
|
|
self.assertEqual(col.id, 3138830)
|
|
self.assertEqual(col.node_id, "MDEzOlByb2plY3RDb2x1bW4zMTM4ODMw")
|
|
self.assertEqual(col.name, "To Do")
|
|
self.assertEqual(col.url, "https://api.github.com/projects/columns/3138830")
|
|
self.assertEqual(col.project_url, "https://api.github.com/projects/1682941")
|
|
self.assertEqual(col.cards_url, "https://api.github.com/projects/columns/3138830/cards")
|
|
self.assertEqual(col.created_at.year, 2018)
|
|
self.assertTrue(col.updated_at >= col.created_at)
|
|
|
|
# See https://developer.github.com/v3/projects/cards/#get-a-project-card
|
|
def testProjectCardAttributes(self):
|
|
proj = self.g.get_project(1682941)
|
|
col = proj.get_columns()[1]
|
|
card = col.get_cards()[0]
|
|
self.assertEqual(card.url, "https://api.github.com/projects/columns/cards/11780055")
|
|
self.assertEqual(card.column_url, "https://api.github.com/projects/columns/3138831")
|
|
self.assertEqual(card.content_url, "https://api.github.com/repos/bbi-yggy/PyGithub/issues/1")
|
|
self.assertEqual(card.id, 11780055)
|
|
self.assertEqual(card.node_id, "MDExOlByb2plY3RDYXJkMTE3ODAwNTU=")
|
|
self.assertEqual(card.note, None) # No notes for cards with content.
|
|
self.assertEqual(card.creator, self.repo.owner)
|
|
self.assertEqual(card.created_at.year, 2018)
|
|
self.assertTrue(card.updated_at >= card.created_at)
|
|
self.assertFalse(card.archived)
|
|
|
|
def testGetProjectCardContent(self):
|
|
proj = self.g.get_project(1682941)
|
|
col = proj.get_columns()[1]
|
|
cards = col.get_cards()
|
|
|
|
pull_card = cards[0]
|
|
pull = pull_card.get_content("PullRequest")
|
|
self.assertIsInstance(pull, github.PullRequest.PullRequest);
|
|
self.assertEqual(pull.title, "Work in progress on support for GitHub projects API.")
|
|
|
|
issue_card = cards[1]
|
|
issue = issue_card.get_content()
|
|
self.assertIsInstance(issue, github.Issue.Issue);
|
|
self.assertEqual(issue.title, "Test issue")
|
|
|
|
note_card = cards[2]
|
|
note_content = note_card.get_content()
|
|
self.assertEqual(note_content, None)
|
|
|
|
def testGetAllProjectCards(self):
|
|
expectedProjects = ['TestProject']
|
|
expectedCards = 5
|
|
projects = []
|
|
cards = 0
|
|
for proj in self.repo.get_projects():
|
|
projects.append(proj.name)
|
|
for col in proj.get_columns():
|
|
for card in col.get_cards("all"):
|
|
cards += 1
|
|
self.assertEqual(projects, expectedProjects)
|
|
self.assertEqual(cards, expectedCards)
|