#14 Adding support to create new project API
Merged 7 years ago by yangl1996. Opened 7 years ago by cverna.
cverna/libpagure get_some_more_api  into  master

file modified
+25 -2
@@ -3,23 +3,46 @@ 

  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'

+ ```

+ 

+ * 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 reference.

+ This library is a Python warp of Pagure web APIs.

+ You can refer to [Pagure API](https://pagure.io/api/0/) reference.

file modified
+30
@@ -490,3 +490,33 @@ 

          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 is not None:

+             payload['namespace'] = namespace

+         if url is not None:

+             payload['url'] = url

+         if avatar_email is not None:

+             payload['avatar_email'] = avatar_email

+         if create_readme is not None:

+             payload['create_readme'] = create_readme

+ 

+         return_value = self.__call_api(request_url, data=payload,

+                                        method='POST')

+ 

+         return return_value['message']

Now supports new_project end point and have some more detailed usage

1 new commit added

  • Fix markdown
7 years ago

1 new commit added

  • Following pep8 comparisons
7 years ago

@sayanchowdhury I have just updated the code. Thanks for the link, it was a useful reading :)

Do we want to split at 80 chars?

One small comment, looks good otherwise

:thumbsup: for me. We can merge after fix for @pingou's suggestion

1 new commit added

  • 80 char limit in README
7 years ago

1 new commit added

  • More changes to README
7 years ago

Pull-Request has been merged by yangl1996

7 years ago

Merged, thank you very much :)

Metadata