The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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

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 '/'

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

url :lvalue

The url for a web hook

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  $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  $gitHub  GitHub object

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  $gitHub  GitHub object
  2  $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  $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  $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  $gitHub  GitHub object

Index

1 branch

2 createPushWebHook

3 delete

4 failed

5 fileList

6 gitFile

7 gitFolder

8 list

9 listWebHooks

10 new

11 personalAccessToken

12 read

13 readData

14 repository

15 response

16 secret

17 url

18 userid

19 write

20 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.