Created
July 4, 2019 14:50
-
-
Save danielappelt/5c1d5bf2058a7b36b5f150fe93522962 to your computer and use it in GitHub Desktop.
Node client to programmatically create a Gitea repo (https://try.gitea.io/api/swagger#/user/createCurrentUserRepo)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// Setup: | |
// npm install node-rest-client | |
// Usage: | |
// node create_gitea_repos.js <repo name> <repo desc> [<gitea url>] [<user>] [<token>] | |
// You may put hardcoded values below instead of using last three arguments. | |
// Create a token in your user's settings at <gitea url>/user/settings/applications | |
var url = process.argv[4] || '', | |
user = process.argv[5] || '', | |
token = process.argv[6] || ''; | |
// See https://www.npmjs.com/package/node-rest-client | |
var Client = require('node-rest-client').Client; | |
// Use gitea user and token for authentication | |
var client = new Client({user: user, password: token}); | |
var args = { | |
data : { name: process.argv[2], | |
description: process.argv[3] }, | |
headers: { "Content-Type": "application/json" } | |
}; | |
client.post(url + '/api/v1/user/repos', args, function (data, response) { | |
// Print parsed response body | |
console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment