Package: github-projectv2
ProjectV2 ClientThis is an in-progress client to use the ProjectV2 functionality through the GitHub GraphQL API.SetupInstall theprojectv2module:pip3 install github-projectv2Create a.envfile in the root containing a value forGITHUB_API_TOKEN(this will be loaded usingpython-dotenv)Use therequirements.txtfile to ensure you have all of the dependencies you need.Enjoy!NOTE:You can use an actual environment variable instead of the.envapproach, setting the sameGITHUB_API_TOKENvalueExample Usagefromprojectv2.projectimportProjectproject=Project()project.get('myorg','1234')print(project.title)# Find the field with the name "Test Field 1"found=Noneforfieldinproject.fields:iffield.name=="Test Field 1":found=fieldiffoundisNone:raiseException("Field not found")items=project.get_items('myorg')print(items)# Look on the project fields and find the one with the name "Test Field 1" and get its options# Then, find the option with the name "Option 1" and get its idforoptioninfound.options:ifoption.name=="test3":newOption=optionforiteminitems:result=item.update_field_value(project,field,newOption)print(result)ModulesProjectTheProjectmodule is used to get the information about a project. It results in an instance with the following properties:title(string)description(string)id(string): internal ID of project recordnumber(integer): public-facing ID number of projectfields(list): Set of fields in the project, default and customitems(list): Set of "items" in the project, usually issue instancesorg(string): Name of the organization the project belongs tocreatedAt(datetime): Date/time of project creationclosedAt(datetime): Date/time when project was closedclosed(boolean): The open/closed state of the projectshortDescription(string): Short description of the projectpublic(boolean): Visibility for the project (public=True, private=False)readme(string): Full readme for the projecturl(string): Full public-facing URL location of the projectNOTE:When thegetmethod is called on theProject, theget_fieldsmethod will automatically be called to populate thefieldsproperty with instances of theFieldclass.Methodsget(org, projectNumber): Get a project by organization name and public-facing project number
Where:org(string): the name of the organizationprojectNumber(string): the public-facing ID for the projectget_fields(org): Get the fields for a project given the organization name and public-facing project number
Where:orgis the name of the organization (optional)get_items(args): Get the items currently in the project (issues)
Whereargsare one or more named variables:org(string) is the name of the organizationoptions(dict) are options for the query (see "Query Options" section below)
Returns:A set ofItemobject typesget_views(args): Get the current list of views for the project
Whereargsare one or more named variables:org(string): optional name of the organizationoptions(dict) are options for the query (see "Query Options" section below)
Returns:A set ofViewobject typescreate(data): Create a new project
Where:data(list): Data to use in the creation of the project (required values:title,ownerId)
Returns:AProjectinstance with the new data setremove_item(item): Removes an item from a project
Where:itemmust be a record as fetched byget_items, not from a call toItem.getReturns:The internal ID of the deleted itemadd_item(item): Adds an item/issue to a project
Where:itemis a record as fetched byItem.getor from the list fromProject.get_itemsReturns:The internal ID of the item that was addedsave(): Saves the current state of the project record (fields saved are title, shortDescription, readme, closed)
Returns:The current instance, aProjectwith the updated informationNOTE:theget_fieldsandget_itemsrequire that the project is fetched usinggetfirst and will throw an error otherwise.ItemTheItemmodule is used to represent an item in a project (an issue record). It results in an instance with the following properties:id(string): internal ID of the item recordtype(string): type of item (ex:ISSUE)created(string): A date/time of when the item was createdassignees(list): A set ofUserinstancestitle(string): Title of the item (issue)number(string): The public-facing number of the itemupdatedAt(string): A date/time of when the item was last updatedurl(string): The public-facing URLbody(string): Unrendered body contentclosed(boolean): Closed/not closed stateclosedAt(string): A date/time of when the issue was closedauthor(list): A set ofUserinstanceslabels(list): A set ofLabelinstancesprojectNodeId(string): The internal ID of the item (used when relating to a project, otherwiseNone)trackedIssues(list): A set ofIteminstancestrackedInIssues(list): A set ofIteminstancesMethodsupdate_field_value(project, field, input): Update a single select field to a new value
Where:project= aProjectinstancefield= aFieldinstance representing the field to update the value onoption= Either an anOptioninstance representing the new value or a string valueget(org, repo, itemId)Where:org(string): the name of the organizationrepo(string): the name of the repositoryitemId(string): the ID number of the itemclear_field_value(project, field)Where:project: aProjectinstancefield: aFieldinstance for the field to clear (a result of the objects loaded from aProject.get_fields()method call)create(repository, data)Where:repository: aRepositoryinstancedata: a data set containing:assigneeIds,body,title(optional:labelIds,milestoneId)OptionTheOptionmodule is used to represent an option on a single-select field. It results in an instance with the following properties:id(string): internal ID of the option recordname(string): the name of the option (this is the option's value)FieldTheFieldmodule is used to represent a field in the project. It results in an instance with the following properties:id(string): internal ID of the field recordname(string): name of the fielddataType(string): type of field (Ex:TEXTorSINGLE_SELECT)options(list): when thedataTypeisSINGLE_SELECTthe options array will be populated with the options records as instances ofOptionLabelTheLabelmodule is used to represent a label on an item. It results in an instance with the following properties:id(string): internal ID of the label recordname(string): name of the labeldescription(string): description of the labelUserTheUsermodule is used to represent a user in the system. It results in an instance with the following properties:id(string): internal ID of the user recordemail(string): email address of the userlogin(string): login/username of the username(string): user's nameMilestoneTheMilestonemodule is used to represent a milestone in the system. It results in an instance with the following properties:id(string): internal ID of the milestone recorddescription(string): description of the milestonenumber(integer): public-facing IDtitle(string): title of the milestonestate(string): open/closed statusdueOn(string): datetime string of when the milestone isMethodsget(org)Where:org(string): the name of the organizationRepositoryTheRepositorymodule is used to represent a repository in the system. It results in an instance with the following properties:id(string): internal ID of the repository recordname(string): name of the repositorydescription(string): repository descriptionisPrivate(boolean): public/private statusisArchived(boolean): archived/not archivedisDisabled(boolean): disabled/not disabledisFork(boolean): is a fork/not a forkisLocked(boolean): is locked/not lockedisMirror(boolean): is a mirror/not a mirrorisTemplate(boolean): is a template/not a templateMethodsget(org, name)Where:org(string): organization namename(string): repository nameget_milestones()NOTE:get_milestonesrequires thatget()is called firstOrganizationTheOrganizationmodule is used to represent an organization in the system. It results in an instance with the following properties:id(string): internal ID of the organization recordname(string): name of the organization (ex:GitHub)login(string): the login of the organization (ex:github)description(string): the description of the organizationcreatedAt(string): datetime stringlocation(string): location value of the organizationurl(string): external URL locationrepositories(list): a list of all repositories in the organization (loads asRepository objects)NOTE:Repositories are not loaded by default.get_repositoriesmust be called to load them. The method will also return the repository list.Methodsget(login)Where:login(string) the name of the organization
Returns:A single object of typeOrganizationget_repositories(login)Where:login(string): the name of the organization (nameis optional, but if not setgetmust be called first)
Returns:A set ofRepositoryclass objects populated with repository dataSearchTheSearchmodule is used to make searches using thesearch()method on the GraphQL API using a format similar to those used in the search on the website.No properties definedMethodsissuesWhere:filter(string): the search filter string
Returns:Set ofItemclass objects populated with matching issue dataViewTheViewmodule represents a view in the project (a tab). It results in an instance with the following properties:id(string): internal ID of the viewnumber(string): the public ID of the viewsortBy(array): populated when a view is sorted (contains:field.name,field.id(internal),field.dataType,direction)groupBy(array): populated when a view is grouped (contains:id(internal),name)layout(string): Layout of the view (ex:TABLE_LAYOUTorBOARD_LAYOUT)Resource:https://mathspp.com/blog/how-to-create-a-python-package-in-2022Query OptionsIn some methods (such asproject.get_items) use can used named arguments to configure the requests made to the API (see method definitions above to determine which support theoptionsnamed variable)Supported options:includeTrackedInIssues: Includes information about the other item(s) the current item is tracked in (Values:True/False)includeTrackedIssues: Include information about the item(s) being tracked by this item  (Values:True/False)