Desarrollo y Mantenimiento de Sistemas Informáticos

4º. 1er cuatrimestre. Itinerario de Sistemas de la Información. Grado en Ingeniería Informática. ULL


Organization DMSI org   Github Classroom DMSI class   Campus Virtual DMSI campus   Profesor Casiano   Chat Chat

Clase del Lunes 2021/11/22

Práctica gh-cli-graphql

Estamos estudiando las extensiones en GitHub Cli:

gh-repo-rename-alu0101227610.js

#! /usr/bin/env node
const ins = require("util").inspect;

const shell = require('shelljs');
const { Command } = require('commander');
const program = new Command();
const { version } = require("./package.json")

program
  .version(version)
  .option('-r, --repo <repo>', 'repository')
  .option('-o, --org <org>', 'org')
  .option('-n, --name <name>', 'name');

program.parse(process.argv);

let args = program.args;
debugger;

let originalName = `${program.opts().name}`;

let { org, repo, name } = program.opts();
// console.log(originalName);

if (!org || ! repo || !name) program.help();

if (!shell.which('git')) shell.echo("git not installed")
if (!shell.which('gh')) shell.echo("gh not installed");

let r = shell.exec(`gh api -X PATCH /repos/${org}/${repo} -f name=${name}`, {silent: true});

let rj = JSON.parse(r.stdout)
console.log(`The repo ${org}/${repo} has been renamed to ${rj.full_name}`);
//console.log(`The repo has been renamed to ${rj.full_name}`);

Package.json

{
  "dependencies": {
    "comander": "^0.0.1-security",
    "commander": "^8.3.0",
    "shelljs": "^0.8.4"
  },
  "name": "gh-repo-rename-alu0101227610",
  "description": "",
  "version": "1.1.0",
  "main": "gh-repo-rename-alu0101227610.js",
  "scripts": {
    "debug": "node --inspect-brk gh-repo-rename-alu0101227610.js -o ULL-ESIT-DMSI-1920 -r prueba-funciona  -n prueba",
    "create-prueba": "gh create-repo prueba ULL-ESIT-DMSI-1920",
    "list-prueba": "gh submodule-add -s prueba -o ULL-ESIT-DMSI-1920 -n",
    "test": "./gh-repo-rename-alu0101227610 -o ULL-ESIT-DMSI-1920 -r prueba  -n prueba-funciona; npm run list-prueba",
    "back": "./gh-repo-rename-alu0101227610 -o ULL-ESIT-DMSI-1920 -r prueba-funciona  -n prueba; npm run list-prueba",
    "start": "node gh-repo-rename-alu0101227610.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/alu0101227610/gh-repo-rename-alu0101227610.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/alu0101227610/gh-repo-rename-alu0101227610/issues"
  },
  "homepage": "https://github.com/alu0101227610/gh-repo-rename-alu0101227610#readme"
}

bash script

#!/usr/bin/env bash

# Determine if an executable is in the PATH
if ! type -p node >/dev/null; then
   echo "Node not found on the system. Can't work" >&2
   exit 1
fi

# ${BASH_SOURCE[0]} (or, more simply, $BASH_SOURCE[1] ) contains the (potentially relative) path of the containing 
# script in all invocation scenarios, notably also when the script is sourced, which is not true for $0.
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

node ${SCRIPT_DIR}/gh-repo-rename-alu0101227610.js "$@"

Entendiendo el script:

#SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SCRIPT_DIR="$( dirname -- "${BASH_SOURCE[0]}" )"
SCRIPT_DIR="$( dirname -- "${BASH_SOURCE[0]}" )"
WITH0="$( dirname -- "$0")"
echo $WITH0 $SCRIPT_DIR

Ejecuciones:

[~/campus-virtual/1920/dmsi1920/apuntes(master)]$ bash /tmp/bash_source 
/tmp/bash_source /tmp
[~/campus-virtual/1920/dmsi1920/apuntes(master)]$ bash /tmp/bash_source 
/tmp /tmp
[~/campus-virtual/1920/dmsi1920/apuntes(master)]$ . /tmp/bash_source 
. /tmp

Empezamos con GraphQL.

GitHub GraphQL Explorer

Ejemplos

Referencias