aboutsummaryrefslogtreecommitdiff
Git Commit to Gnu-Social
-------------------------


About
-----
gc2gs is a shellscript that posts a status message to a gnu-social node with
the last commit information of a git-project. It can be used with gnu-social
and pleroma instances as well (cause they are supposed to share api).


Install 'systemwide'
--------------------
Clone repository and copy the script into proper location (i.e. /usr/bin)


  ~$ cd /tmp

  /tmp$ git clone https://git.p4g.club/git/gc2gs.git gc2gs && cd

  ~$ sudo cp gc2gs/gc2gs.sh /usr/bin/gc2gs

  ~$ sudo chmod +x /usr/bin/gc2gs && cd

  ~$ rm -rf /tmp/gc2gs


If manually run is prefered, just clone repository and run from within
script directory.


Usage
-----
Once installed, run it with no arguments to show help message.


  ~ $ gc2gs

----------------
gc2gs version...
  License: The Drunken BEER License v 1.1 (https://git.p4g.club/git/beer/about)

gc2gs is a shellscript that posts a status message to a
  gnu-social node with the last commit information of a git-project

Usage:  /usr/bin/gc2gs [OPTIONS] <args> ...
Usage:  /usr/bin/gc2gs [-[ckp]vh] projectname

Options
   -c   <projectname>   Create a configuration file for 'projectname'
   -k   <projectname>   Create a 'pre-push' 'git hook' for 'projectname'
   -p   <projectname>   Post a status message with 'projectname' last commit 
                        information. Usefull when running script manually
   -v   VERBOSE         Increase verbosity
   -h   HELP            Print this help and exit

For more details about this script go to
Official Repository: https://git.p4g.club/git/gc2gs
Mirror Repository: https://gitgud.io/ziggys/gc2gs
----------------


Configure (-c)
--------------
gc2gs uses 'project.config' files to obtain input variables. This files are
stored in '${XDG_HOME_CONFIG}/gc2gs' directory and can be created and modified
manually by user. Obviously, you can configure and create as many 
'project.config' files as git projects you want to manage to post commits into
your gnu-social node.


To create a 'project.config' file using script, run:


  $ gc2gs -c projectname


This command will ask several questions to create configuration file for
'projectname' (i.e. '~/.config/gc2gs/myproject.config'). If you already have
a 'myproject.config' file, it will ask if you want to overwrite and start over
with a new one configuration file.


---------------
Configuring a new project.config file for myproject

Please enter your gnu-social account information
'username' (i.e. 'me@myno.de', 'username=me'): username
'password' (your 'plain-text password'): password
'node' (url w/o trainling slash 'https://myno.de'): https://social.mynode.io

Please enter your git project information
git project (the name of your git repository): myproject
project url (https://git.reposito.ry/me/project):
https://git.platform.io/me/myproject
project path (i.e. /home/ziggys/git/myrepo ): /home/me/git/myproject
platform (cgit | gitlab | github | gitea | other): cgit

Populating /home/me/.config/gc2gs/myproject.config...

do you want to configure an automatic 'pre-push' 'git hook'? (yes/no): no
done!
--------------


At the end, the scripts asks if you want to configure a 'pre-push' 'git-hook'.
This section will be addressed later on 'git-hook' configuration section. If
you intend to run the script manually everytime you want to post commits to
gnu-social, answer 'no' and just ignore 'git-hook' configuration section.


Last command will result in creation of 'myproject.config' file in proper
directory. While this file contains sensible data, some variables will be
obfuscated and file will have 0600 type permissions (write and read only for
owner).


  ~$ ls -l ".config/gc2gs/myproject.config" | awk '{print $1 "\t" $3 "\t" $9}'

--------------
-rw-------    me    myproject.config
--------------


  ~$ cat .config/gc2gs/myproject.config

----------------
USER=dXNlcm5hbWUK;
PASSWORD=cGFzc3dvcmQK;
NODE=https://social.mynode.io;
PROJECT=myproject;
PROJECTURL=https://git.platform.io/me/myproject;
REPOPATH=/home/me/git/myproject;
PLATFORM=cgit;
----------------


As seen, 'myprojec.config' has read and write permissions only for user 'me'
and username/password where ofuscated.


Configure 'project.config' manually
-----------------------------------
To configure a 'project.config' file manually, just create configuration
directory and edit file properly. To do that, obtain obfuscated username
and password and edit variables with resultant output.


 ~$ echo "username" | base64 -

----------------
dXNlcm5hbWUK
----------------


 ~$ echo "password" | base64 -

----------------
cGFzc3dvcmQK
----------------


Edit the file:


  ~$ mkdir -p .config/gc2gs && vim .config/gc2gs/myproject.config


This manually edition is particulary usefull for password changes and
multiple projects with same gnu-social account information. Serve as
you wish.


Configure a 'pre-push' 'git-hook' (-k)
--------------------------------------
When 'Configure (-c)' asked to create a 'git-hook' the answer was 'no'
because an automatic 'pre-push' 'git-hook' script was not wanted to be
configured for 'myproject'. Let's asume we want to do that now, this is,
configure a 'pre-push' 'git-hook' so everytime we push our last commit 
changes to remote repository, a script will automatically post a status
message with commit information. 

To do that, run the script with '-k' option (i.e. for 'myproject'):


  ~$ gc2gs -k myproject

---------------
Configuring a 'pre-push' 'git hook' for myproject

done!
---------------


Let's check if everything go well:

  ~$ ls ~/git/myproject/.git/hooks | grep "pre-push"

----------------
pre-push
pre-push.sample
----------------


If we should 'cat' the 'pre-push' file, we will see a slightly modified copy of
the 'snippet' file in 'snippet' directory within this repository. The modified
part is a variable in the snippet named 'CONFNAME' and is a call to the file
'project.config'. Let's check this out:

  
  ~$ sed '/CONFNAME=/ !d' "~/git/myproject/.git/hooks/pre-push"

----------------
CONFNAME=myproject
----------------


Post (-p)
---------
Now we have configured properly, it's time to start posting status messages to
gnu-social with the last commit information of our git projects. To achieve
that for 'myproject', run:

  
  ~$ gc2gs -p myproject

----------------
A status message was posted on https://social.mynode.io by username
----------------


Let's check the message in our gnu-social node, and we will see
something like this in our last status post:


----------------
 username
 The myproject project

 | New commit on branch master by me (at 09-06 17:13):

 Commit message (commit_id-fingerprint)

 commit_url: https://git.platform.io/me/myproject/commit/?h=master

 project_url: https://git.pĺatform.io/me/myproject
 a few seconds ago from gc2gs permalink 
----------------


Credits and Thanks
------------------
I should give some credit to those who inspired and also helped with the
creation of this script (although they probably do not know, yet).

-- stormdragon (https://stormdragon.tk) who provided the basics and a lot
of code to this script (see https://stormdragon.tk/git-hooks-and-gnu-social)

-- drymer (https://daemons.it) who gave inspiration through another script
(https://git.daemons.it/drymer/gnusrss)

-- xiku (alias xikucapo) (https://agora.p4g.club), the man behind the scene
we call "el jefe"

-- sathariel (https://iro-iro.xyz), who's always willing to review and correct
the code

-- the community on gnu-social (specially in https://bobinas.p4g.club node)
and gitgud.io who's always patient with drunken non-developers like me, always
playing with fire

-- myself for being such an good fellow (no matter what everyone else says)


License
-------
This work is licensed under "The Drunken BEER License  v-1.1"


For a copy and a full license description, read the LICENSE file within
repository.


TODO (ziggys)
-------------
# Finish this README.txt
# Check gc2gs.sh syntax
# Check snippet syntax
# Other minor changes