4º. 1er cuatrimestre. Itinerario de Sistemas de la Información. Grado en Ingeniería Informática. ULL
Estamos estudiando las extensiones en GitHub Cli:
#! /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;
const getRepoId = (owner, newName) => `
query {
  repository(owner: "${owner}", name: "${newName}") {
    id
  }
}
`;
const renameRepo = (id) => `
mutation {
  updateRepository(input: {name: "prueba-funciona", repositoryId: ${id}}) {
    repository {
      name
    }
  }
}
`;
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}`);
*/
console.log(getRepoId("ULL-MFP-AET-2122", "nuevonombredelrepo"))
➜  gh-cli-graphql-casiano-rodriguez-leon-alumnoudv5 git:(main) node gh-repo-rename-alu0101227610.js -o dfjshjdhjdf -n sfkjsdgjdg -r kfjddjfhgdhfj
query {
  repository(owner: "ULL-MFP-AET-2122", name: "nuevonombredelrepo") {
    id
  }
}
{
  "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"
}
#!/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
Node.js 8 the Right Way GitHub. versión de 2013.
Node.js in Action, Second Edition by: Bradley Meck Alex Young and Mike Cantelon. Acceda por medio del PuntoQ de la ULL