GitHub::Crud - Create, Read, Update, Delete files on GitHub.
Create, Read, Update, Delete files on GitHub as described at:
https://developer.github.com/v3/repos/contents/#update-a-file
and also copy files, rename files and check whether files exist.
sudo apt-get install curl
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 = "..."; say STDERR "Write : ", dump($g->write(join '-', 1..9)), "\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
The following sections describe the methods in each functional area of this module. For an alphabetic listing of all methods by name see Index.
Create a new() object and then set these attributes to specify your request to GitHub
The body of an issue
Branch name (you should create this branch first) or omit it for the default branch which is usually 'master'
Defined if the last request to Github failed else undef.
Reference to an array of files produced by list
File name on GitHub - this name can contain '/'. This is the file to be read from, written to, copied from, checked for existence or deleted
Folder name on GitHub - this name can contain '/'
The name of a local file to which to write error messages if any errors occur.
Optional commit message
Do a non recursive list - the default is to list all the sub folders found in a folder but this takes too much time if you are only interested in the files in the start folder
A personal access token with scope "public_repo" as generated on page: https://github.com/settings/tokens
The folder into which to save personal access tokens. Set to q(/etc/GitHubCrudPersonalAccessToken) by default.
Data produced by read
The name of your repository minus the userid - you should create this repository first manually.
A reference to GitHub's response to the latest request
The secret for a web hook - this is created by the creator of the web hook and remembered by GitHuib
The title of an issue
The url for a web hook
Send the data as utf8 - do not use this for binary files containing images or audio, just for files containing text
Your userid on GitHub
Data to be written by write
Create a new GitHub object.
List all the files contained in a GitHub repository or all the files below a specified folder in the repository.
Required parameters: userid, repository.
Optional parameters: gitFolder, refOrBranch, nonRecursive, patKey.
Use the gitFolder parameter to specify the folder to start the list from, by default, the listing will start at the root folder of your repository.
Use the nonRecursive option if you require only the files in the start folder as otherwise all the folders in the start folder will be listed as well which might take some time.
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.
Parameter Description 1 $gitHub GitHub object
Read data from a file on GitHub.
Required parameters: userid, repository, gitFile = the 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.
Parameter Description 1 $gitHub GitHub object 2 $noLog Whether to log errors or not
Write data into a GitHub file, creating the file if it is not already present.
Required parameters: userid, repository, patKey, , gitFile = the file to be written to.
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.
Parameter Description 1 $gitHub GitHub object 2 $data Data to be written
Copy a source file from one location to another target location in your GitHub repository, overwriting the target file if it already exists.
Required parameters: userid, repository, patKey, gitFile = the file to be copied.
Parameter Description 1 $gitHub GitHub object 2 $target The name of the file to be created
Test whether a file exists on GitHub or not and returns an object including the sha and size fields if it does else undef.
Required parameters: userid, repository, gitFile file to test.
Rename a source file on GitHub if the target file name is not already in use.
Required parameters: userid, repository, patKey, gitFile = the file to be renamed.
Returns the new name of the file renamed if the rename was successful else undef if the rename failed.
Parameter Description 1 $gitHub GitHub object 2 $target The new name of the file
Delete a file from GitHub.
Required parameters: userid, repository, patKey, gitFile = the file to be deleted.
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.
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.
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.
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.
Save the personal access token by userid in folder personalAccessTokenFolder().
Load the personal access token by userid from folder personalAccessTokenFolder().
1 body
2 branch
3 copy
4 createIssue
5 createPushWebHook
6 delete
7 exists
8 failed
9 fileList
10 gitFile
11 gitFolder
12 list
13 listWebHooks
14 loadPersonalAccessToken
15 logFile
16 message
17 new
18 nonRecursive
19 personalAccessToken
20 personalAccessTokenFolder
21 read
22 readData
23 rename
24 repository
25 response
26 savePersonalAccessToken
27 secret
28 title
29 userid
30 utf8
31 webHookUrl
32 write
33 writeData
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
philiprbrenan@gmail.com
http://www.appaapps.com
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.
To install GitHub::Crud, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GitHub::Crud
CPAN shell
perl -MCPAN -e shell install GitHub::Crud
For more information on module installation, please visit the detailed CPAN module installation guide.