About Github Connect

ProcessWire module to connect a Github OAuth application.

Category 1Input Fields
Inputfield modules that provide a UI input widget in the ProcessWire admin.
Category 2Markup Generation
Markup modules that are called upon to generate or parse markup (like HTML). Markup modules are most often used on the front-end of a site (rather than admin).
Category 3Social, Feeds, Services
Modules that provide or work with social networking services and/or external feeds.
Release StateBeta
Close to stable, but users are advised to be cautious and test thoroughly.*
Authorjustb3a
Module Version0.0.4
Class NameGithubConnect
Compatibility3.0
Date AddedMarch 10, 2017
Last UpdatedMarch 15, 2017
Recommended ByNew recommendations may take up to 1 day to appear.

Instructions

This module's files should be placed in /site/modules/GithubConnect/
How to install or uninstall modules

README

ProcessWire GithubConnect

ProcessWire module to connect a Github OAuth application.

Generate Access Token

Register a new OAuth application

You have to create an OAuth application to get appId and appSecret. Those keys are required.
Go to Github and add a new OAuth application.
Therefore you've to fill in a redirect uri, copy it from module settings.Congrats! Now you can copy your unique Client ID and Client Secret

Fill in module settings

Fill in the following fields:

  • organization
  • Github Client ID
  • Github Client Secret

Now save module settings.
Click the Authorize! link to generate code and access token.
Now the field Github Access Token should be filled.

Endpoints

Usage Example

$github = $modules->get('GithubConnect');
$github->setRepository('owner/repository');
$result = $github->getRepositoryInformations();

Set the Repository

You can set a repository initially. So you don't have to pass it every time.

$github->setRepository('owner/repository');

  • params
    • name of repository, scheme: :owner/:repo (string)

Get Repository Informations

Get informations about a repository.

$github->getRepositoryInformations($repo);

  • see Github Api (to get the complete documentation and an example response)
  • params
    • optional name of repository, scheme: :owner/:repo (string)
  • return array

Get the readme

Get informations about the README file.

$github->getReadme($repo);

  • see Github Api (to get the complete documentation and an example response)
  • params
    • optional name of repository, scheme: :owner/:repo (string)
  • return array

Get the content

Get base64 decoded content of a file.

$github->getContent($data);

  • params
    • result data for example from $github->getReadme($repo); (array)
  • return string

Get the readme content

Get base64 decoded content of a the README.

$github->getReadmeContent($repo);

  • params
    • optional name of repository, scheme: :owner/:repo (string)
  • return string

Get certain file

Get informations about a certain file.

$github->getFile($filename, $repo);

  • see Github Api (to get the complete documentation and an example response)
  • params
    • filename
    • optional name of repository, scheme: :owner/:repo (string)
  • return array

Get content of certain file

Get base64 decoded content of a certain file.

$github->getContentOfAFile($filename, $repo);

  • see Github Api (to get the complete documentation and an example response)
  • params
    • filename
    • optional name of repository, scheme: :owner/:repo (string)
  • return string

List repositories for the specified org

List all repositories for an specified organization.

$github->listRepositoriesByOrg($org);

  • see Github Api (to get the complete documentation and an example response)
  • params
    • optional name of an organization (defaults to entry from module settings)
  • return array

Get a Tree

Get a tree of a github repository by a sha.

A sha, or "hash", is an individual change to a file or a directory.Every time you save a file with git, it creates a unique ID (a.k.a. the "SHA" or "hash") that allows you to keep record of what changes were made when and by who. Instead of a sha you can also use the name of a branch.

$github->getTree($sha, $recursive, $repo);

  • see Github Api (to get the complete documentation and an example response)
  • params
    • optional sha defaults to branch master
    • optional recursive defaults to true
    • optional name of repository, scheme: :owner/:repo (string)
  • return array

Use predefined autofill functionality

Create two templates:

  • A to get the content of the readme
  • B to get the content of a file inside a repository

Create the following fields:

identTypeassign to templatedescription
fieldSelectOptionA + BField which should be filled with Github repositories.
fieldSubSelectOptionBField which should be filled with files of a Github repository.
fieldPlainTextA + BField which should store the selected Github repository.
fieldTeaserTextareaAField which should contain the imported description content (a.k.a. teaser).
fieldBodyTextareaA + BField which should contain the imported file content.

Add the fields to the appropriate template(s).Assign the created fields in module settings.

Example

Create the following fields:

  • repositories: Type Option
  • repository_tree: Type Option
  • repository: Type Text
  • description: Type Textarea
  • body: Type Textarea

Create two templates and assign the fields:

  • Template github-main, assign fields:
    • repositories
    • repository
    • description
    • body
  • Template github-sub, assign fields:
    • repositories
    • repositoryTree
    • repository
    • body

Fill in module settings

  • enable Backend Import Features
  • (1) choose field repositories
  • (2) choose field repository
  • (3) choose field description
  • (4) choose field body
  • (5) choose field repository_tree

Create a new page with template github-main

  • you'll get a list of all available Github repositories, choose one and click save
  • after the page has been reloaded, the following fields are filled:
    • repository: contains the chosen repository
    • description: contains the description of the repository
    • body: contains the content of the readme
  • as long as you're not choose a repository from the list again (field repositories), the content won't be changed or overwritten

Create a new page with template github-sub

  • you'll get a list of all available Github repositories, choose one and click save
  • after the page has been reloaded, the following fields are filled:
    • repository: contains the chosen repository
    • repository_tree: here you'll see a list of all files from the chosen repository
  • choose one of the files listed there and click save
  • after the page has been reloaded, the following fields are filled:
    • body: contains the content of the readme
  • as long as you're not choose a repository from the list again (field repositories) or another file (field repository_tree), the content won't be changed or overwritten

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.