Name

GitHub::Crud - Create, Read, Update, Delete files on GitHub.

Synopsis

Create, Read, Update, Delete files on GitHub as described at:

https://developer.github.com/v3/repos/contents/#update-a-file

Prerequisites

sudo apt-get install curl

Example

Create a file by writing some of data to it, read the file to get its contents, delete the file, then try to read the deleted file again:

use GitHub::Crud;

 my $g = GitHub::Crud::new();
    $g->userid              = "...";
    $g->repository          = "test";
    $g->gitFile             = "test.html";
    $g->personalAccessToken = "...";

 my $d = join '-', 1..9;

 say STDERR
    "Write : ", dump($g->write($d)),
  "\nRead 1: ", dump($g->read),
  "\nDelete: ", dump($g->delete),
  "\nRead 2: ", dump($g->read);

Produces:

Write : 'created';
Read 1: "1-2-3-4-5-6-7-8-9"
Delete: 1
Read 2: undef

Description

The following sections describe the methods in each functional area of this module. For an alphabetic listing of all methods by name see Index.

Attributes

Create a new() object and then set these attributes to specify your request to GitHub

body :lvalue

The body of an issue

branch :lvalue

Branch name (you should create this branch first) or omit it for the default branch which is usually 'master'

failed :lvalue

Defined if the last request to Github failed else undef.

fileList :lvalue

Reference to an array of files produced by list

gitFile :lvalue

File name on GitHub - this name can contain '/'

gitFolder :lvalue

Folder name on GitHub - this name can contain '/'

logFile :lvalue

The name of a local file to which to write error messages if any errors occur.

message :lvalue

Commit message

personalAccessToken :lvalue

A personal access token with scope "public_repo" as generated on page: https://github.com/settings/tokens

readData :lvalue

Data produced by read

repository :lvalue

The name of your repository - you should create this repository first

response :lvalue

A reference to GitHub's response to the latest request

secret :lvalue

The secret for a web hook - this is created by the creator of the web hook and remembered by GitHuib

title :lvalue

The title of an issue

url :lvalue

The url for a web hook

utf8 :lvalue

Send the data as utf8 - do not use this for binary files containing images or audio, just for files containing text

userid :lvalue

Your userid on GitHub

writeData :lvalue

Data to be written by write

Methods available

new()

Create a new GitHub object.

list($)

List the files and folders in a GitHub repository.

Required parameters: userid, repository.

Optional parameters: gitFolder, refOrBranch, patKey.

If the list operation is successful, failed is set to false and fileList is set to refer to an array of the file names found.

If the list operation fails then failed is set to true and fileList is set to refer to an empty array.

Returns the list of file names found or empty list if no files were found.

1  Parameter  Description    
2  $gitHub    GitHub object  

read($$)

Read data from a file on GitHub.

Required parameters: userid, repository, gitFile file to read.

Optional parameters: refOrBranch, patKey.

If the read operation is successful, failed is set to false and readData is set to the data read from the file.

If the read operation fails then failed is set to true and readData is set to undef.

Returns the data read or undef if no file was found.

1  Parameter  Description                   
2  $gitHub    GitHub object                 
3  $noLog     Whether to log errors or not  

write($$)

Write data into a GitHub file, creating the file if it is not already present.

Required parameters: userid, repository, gitFile, patKey, writeData.

Optional parameters: refOrBranch.

If the write operation is successful, failed is set to false otherwise it is set to true.

Returns updated if the write updated the file, created if the write created the file else undef if the write failed.

1  Parameter  Description         
2  $gitHub    GitHub object       
3  $data      Data to be written  

delete($)

Delete a file already present on GitHub.

Required parameters: userid, repository, gitFile, patKey.

Optional parameters: refOrBranch.

If the delete operation is successful, failed is set to false otherwise it is set to true.

Returns true if the delete was successful else false.

1  Parameter  Description    
2  $gitHub    GitHub object  

listWebHooks($)

List web hooks.

Required: userid, repository, patKey.

If the list operation is successful, failed is set to false otherwise it is set to true.

Returns true if the list operation was successful else false.

1  Parameter  Description    
2  $gitHub    GitHub object  

createPushWebHook($)

Create a web hook.

Required: userid, repository, url, patKey.

Optional: secret.

If the create operation is successful, failed is set to false otherwise it is set to true.

Returns true if the web hook was created successfully else false.

1  Parameter  Description    
2  $gitHub    GitHub object  

createIssue($)

Create an issue.

Required: userid, repository, body, title.

If the operation is successful, failed is set to false otherwise it is set to true.

Returns true if the issue was created successfully else false.

1  Parameter  Description    
2  $gitHub    GitHub object  

savePersonalAccessToken($$)

Save the personal access token in a file.

1  Parameter  Description                                                           
2  $gitHub    GitHub object                                                         
3  $file      Optional access file - default is /etc/GitHubCrudPersonalAccessToken  

loadPersonalAccessToken($$)

Load a personal access token from a file.

1  Parameter  Description                                                           
2  $gitHub    GitHub object                                                         
3  $file      Optional access file - default is /etc/GitHubCrudPersonalAccessToken  

Index

1 body

2 branch

3 createIssue

4 createPushWebHook

5 delete

6 failed

7 fileList

8 gitFile

9 gitFolder

10 list

11 listWebHooks

12 loadPersonalAccessToken

13 logFile

14 message

15 new

16 personalAccessToken

17 read

18 readData

19 repository

20 response

21 savePersonalAccessToken

22 secret

23 title

24 url

25 userid

26 utf8

27 write

28 writeData

Installation

This module is written in 100% Pure Perl and, thus, it is easy to read, use, modify and install.

Standard Module::Build process for building and installing modules:

perl Build.PL
./Build
./Build test
./Build install

Author

philiprbrenan@gmail.com

http://www.appaapps.com

Copyright

Copyright (c) 2016-2017 Philip R Brenan.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.