From c84a400c6f4b31b5e4260a09e90c142cd3081fe6 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Oct 30 2016 20:23:56 +0000 Subject: [PATCH 1/7] Added basic usage to README Signed-off-by: Clement Verna --- diff --git a/README.md b/README.md index 33ad5e1..00742a8 100644 --- a/README.md +++ b/README.md @@ -3,23 +3,36 @@ A Python library for Pagure APIs. Pagure is a light-weight git-centered forge based on pygit2, created by Pierre-Yves Chibon. ## Installation +--- Use pip to install. ### Linux +--- ``` pip3 install libpagure ``` ### OS X +--- ``` python3 -m pip install libpagure ``` ## Usage +--- +* Import and Initialization: +``` +>>> from libpagure import Pagure +>>> pg = Pagure() +``` -A detailed doc is on the way :) +* Get the API version +``` +>>> pg.api_version() +'0.8' +``` This library is a Python warp of Pagure web APIs, so you may refer to Pagure API reference. From dbb984f877aa2a84df83095bc95467299faedfa0 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Nov 02 2016 19:45:49 +0000 Subject: [PATCH 2/7] Added create new project api Signed-off-by: Clement Verna --- diff --git a/libpagure/libpagure.py b/libpagure/libpagure.py index bc0a777..077c6a9 100644 --- a/libpagure/libpagure.py +++ b/libpagure/libpagure.py @@ -490,3 +490,33 @@ class Pagure(object): return_value = self.__call_api(request_url) return return_value + + def new_project(self, name, description, namespace=None, url=None, + avatar_email=None, create_readme=False): + """ + Create a new project on the pagure instance + :param name: the name of the new project. + :param description: A short description of the new project. + :param namespace: The namespace of the project to fork + :param url: A url providing more information about the project. + :param avatar_email: An email address for the avatar of the project. + :param create_readme: Boolean to specify if there should be a + readme added to the project on creation. + :return: + """ + request_url = "{}/api/0/new".format(self.instance) + + payload = {'name': name, 'description': description} + if namespace: + payload['namespace'] = namespace + if url: + payload['url'] = url + if avatar_email: + payload['avatar_email'] = avatar_email + if create_readme: + payload['create_readme'] = create_readme + + return_value = self.__call_api(request_url, data=payload, + method='POST') + + return return_value['message'] From 148432599dda1303b27de30fcfe70f2a2e0d755f Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Nov 02 2016 20:08:34 +0000 Subject: [PATCH 3/7] Added more usage description Signed-off-by: Clement Verna --- diff --git a/README.md b/README.md index 00742a8..f6f9e59 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,12 @@ python3 -m pip install libpagure '0.8' ``` -This library is a Python warp of Pagure web APIs, so you may refer to Pagure API reference. +* Create a new Project +``` +>>> from libpagure import Pagure +>>> pg = Pagure(pagure_token="foobar") +>>> pg.new_project(name="foo", description="bar", url="http://foobar.io", create_readme=True) +>>> Project "foo" created +``` + +This library is a Python warp of Pagure web APIs, so you may refer to [Pagure API] (https://pagure.io/api/0/) reference. From 4d804a2f19a1ccd328c262377621befecb1e879c Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Nov 02 2016 20:11:48 +0000 Subject: [PATCH 4/7] Fix markdown Signed-off-by: Clement Verna --- diff --git a/README.md b/README.md index f6f9e59..0273139 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,4 @@ python3 -m pip install libpagure >>> Project "foo" created ``` -This library is a Python warp of Pagure web APIs, so you may refer to [Pagure API] (https://pagure.io/api/0/) reference. +This library is a Python warp of Pagure web APIs, so you may refer to [Pagure API](https://pagure.io/api/0/) reference. From fe87020af9d312a5720f4aca975299ef3f658465 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Nov 03 2016 19:25:12 +0000 Subject: [PATCH 5/7] Following pep8 comparisons Signed-off-by: Clement Verna --- diff --git a/libpagure/libpagure.py b/libpagure/libpagure.py index 077c6a9..b97699c 100644 --- a/libpagure/libpagure.py +++ b/libpagure/libpagure.py @@ -507,13 +507,13 @@ class Pagure(object): request_url = "{}/api/0/new".format(self.instance) payload = {'name': name, 'description': description} - if namespace: + if namespace is not None: payload['namespace'] = namespace - if url: + if url is not None: payload['url'] = url - if avatar_email: + if avatar_email is not None: payload['avatar_email'] = avatar_email - if create_readme: + if create_readme is not None: payload['create_readme'] = create_readme return_value = self.__call_api(request_url, data=payload, From 052c9d6fa1e9936874abda410521c4a97d231962 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Nov 04 2016 19:44:30 +0000 Subject: [PATCH 6/7] 80 char limit in README Signed-off-by: Clement Verna --- diff --git a/README.md b/README.md index 0273139..6124f81 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,5 @@ python3 -m pip install libpagure >>> Project "foo" created ``` -This library is a Python warp of Pagure web APIs, so you may refer to [Pagure API](https://pagure.io/api/0/) reference. +This library is a Python warp of Pagure web APIs. +You may refer to [Pagure API](https://pagure.io/api/0/) reference. From 6fc14461724439f03a09590620f5dac0d856058e Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Nov 04 2016 19:46:58 +0000 Subject: [PATCH 7/7] More changes to README Signed-off-by: Clement Verna --- diff --git a/README.md b/README.md index 6124f81..8245bc1 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,10 @@ python3 -m pip install libpagure ``` >>> from libpagure import Pagure >>> pg = Pagure(pagure_token="foobar") ->>> pg.new_project(name="foo", description="bar", url="http://foobar.io", create_readme=True) +>>> pg.new_project(name="foo", description="bar", url="http://foobar.io", + create_readme=True) >>> Project "foo" created ``` This library is a Python warp of Pagure web APIs. -You may refer to [Pagure API](https://pagure.io/api/0/) reference. +You can refer to [Pagure API](https://pagure.io/api/0/) reference.