Comparing version 1.3.2 to 1.4.0
109
index.js
@@ -105,9 +105,39 @@ const axios = require('axios'); | ||
//////////////////////////////// | ||
// inviteGitHubCollaborators // | ||
////////////////////////////// | ||
/////////////////////// | ||
// deleteGitHubRepo // | ||
///////////////////// | ||
async function deleteGitHubRepos(org, repos, token) { | ||
try { | ||
// Get org repo URL | ||
const filePath = path.join(__dirname, 'github/api.properties'); | ||
const config = readPropertiesFile(filePath); | ||
const deleteRequests = repos.map(async repo => { | ||
const replacements = { | ||
organization: org, | ||
repository: repo | ||
}; | ||
return await axios.delete(replacePlaceholders(config.repospecificurl, replacements), { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}); | ||
return await Promise.all(deleteRequests); | ||
} catch (error) { | ||
// Handle error if needed | ||
console.error('Error deleting GitHub repos:', error); | ||
throw error; // Re-throw the error if needed | ||
} | ||
} | ||
///////////////////////////////////// | ||
// inviteGitHubReposCollaborators // | ||
/////////////////////////////////// | ||
/* | ||
@param org = String | ||
@param repo = String | ||
@param collaborators = array | ||
@param repos = Array | ||
@param collaborators = Array | ||
@param token = String | ||
@@ -150,30 +180,44 @@ */ | ||
/////////////////////// | ||
// deleteGitHubRepo // | ||
///////////////////// | ||
async function deleteGitHubRepos(org, repos, token) { | ||
try { | ||
// Get org repo URL | ||
const filePath = path.join(__dirname, 'github/api.properties'); | ||
const config = readPropertiesFile(filePath); | ||
///////////////////////////////////// | ||
// removeGitHubReposCollaborators // | ||
/////////////////////////////////// | ||
/* | ||
@param org = String | ||
@param repos = Array | ||
@param collaborators = Array | ||
@param token = String | ||
*/ | ||
async function removeGitHubReposCollaborators(org, repos, collaborators, token) { | ||
// Get org repo url | ||
const filePath = path.join(__dirname, 'github/api.properties'); | ||
const config = readPropertiesFile(filePath); | ||
const deleteRequests = repos.map(async repo => { | ||
const replacements = { | ||
organization: org, | ||
repository: repo | ||
}; | ||
return await axios.delete(replacePlaceholders(config.repospecificurl, replacements), { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}); | ||
try { | ||
// Remove collaborators for each repository | ||
await Promise.all(repos.map(async repo => { | ||
await Promise.all(collaborators.map(async collaborator => { | ||
const replacements = { | ||
organization: org, | ||
repository: repo, | ||
collaborator: collaborator | ||
}; | ||
return await Promise.all(deleteRequests); | ||
} catch (error) { | ||
// Handle error if needed | ||
console.error('Error deleting GitHub repos:', error); | ||
throw error; // Re-throw the error if needed | ||
} | ||
try { | ||
await axios.delete(replacePlaceholders(config.repourlcollaborator, replacements), { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
Accept: 'application/vnd.github.v3+json', | ||
}, | ||
}); | ||
console.log(`Collaborator ${collaborator} removed from ${repo}`); | ||
} catch (error) { | ||
console.error(`Error removing ${collaborator} from ${repo}:`, error.response ? error.response.data : error.message); | ||
} | ||
})); | ||
})); | ||
console.log('Collaborators removed successfully.'); | ||
} catch (error) { | ||
console.error('Error removing collaborators:', error.response ? error.response.data : error.message); | ||
} | ||
} | ||
@@ -184,3 +228,4 @@ | ||
deleteGitHubRepos, | ||
inviteGitHubReposCollaborators | ||
inviteGitHubReposCollaborators, | ||
removeGitHubReposCollaborators | ||
}; |
{ | ||
"name": "jwz", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"description": "Utils", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -5,3 +5,4 @@ # `Function` | ||
- [deleteGitHubRepos](#deletegithubrepos) | ||
- [inviteGitHubCollaborators](#invitegithubcollaborators) | ||
- [inviteGitHubReposCollaborators](#invitegithubreposcollaborators) | ||
- [removeGitHubReposCollaborators](#removegithubreposcollaborators) | ||
#### `buildGitHubRepos` | ||
@@ -28,5 +29,22 @@ - `usage` | ||
``` | ||
### `inviteGitHubCollaborators` | ||
### `deleteGitHubRepos` | ||
- `usage` | ||
``` | ||
import { deleteGitHubRepos } from "jwz"; | ||
/* | ||
@param org = String | ||
@param repo = Array | ||
@param token = String | ||
*/ | ||
const org = 'your-org-name'; | ||
var repos = ['your-repoA', 'your-repoB']; | ||
const token = 'your-token'; | ||
deleteGitHubRepos(org, repos, token) | ||
``` | ||
### `inviteGitHubReposCollaborators` | ||
- `usage` | ||
``` | ||
import { inviteGitHubReposCollaborators } from "jwz"; | ||
@@ -50,10 +68,11 @@ | ||
- when code is running it will have output of result | ||
### `deleteGitHubRepos` | ||
### `removeGitHubReposCollaborators` | ||
- `usage` | ||
``` | ||
import { deleteGitHubRepos } from "jwz"; | ||
import { removeGitHubReposCollaborators } from "jwz"; | ||
/* | ||
@param org = String | ||
@param repo = Array | ||
@param repos = Array | ||
@param collaborators = Array | ||
@param token = String | ||
@@ -63,6 +82,7 @@ */ | ||
const org = 'your-org-name'; | ||
var repos = ['your-repoA', 'your-repoB']; | ||
var repo = ['your-repoA', 'your-repoB']; | ||
var collaborators = ['collaboratorA', 'collaboratorB'] | ||
const token = 'your-token'; | ||
deleteGitHubRepos(org, repos, token) | ||
removeGitHubReposCollaborators(org, repos, collaborators, token); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11479
203
85