-
Notifications
You must be signed in to change notification settings - Fork 1
Shitty God Mode: Debugging User Management Utilities
Jorge Silva edited this page May 24, 2016
·
6 revisions
An easier way is to do all this is to just install this Chrome extension: https://github.com/Runnable/button-clicker
There are a couple of useful functions that people can use from the inside runnable-angular in order to do some common actions related to debugging and user management
-
inject
: Use any service from Runnable Angular -
getGithubOrgId
: Given the name of an org, get its ID from Github -
deleteAllInvitations
: Delete all invitations for a current org -
whiteListOrg
: Given an org name, whitelist an org -
loginAsUser
: Given a GH access token, login to Runnable as that user -
getInstances
: Get all instances with a repo name and/or branch name -
deleteInstances
: Delete all instances with a repo name and/or branch name
// Here You can type your custom JavaScript...
var inject = function (serviceName) {
var service = angular.element(document.body).injector().get(serviceName);
window[serviceName] = service;
return service;
};
var getGithubOrgId = function (name) {
inject('$http');
inject('configAPIHost');
return $http({
method: 'get',
url: configAPIHost + '/github/orgs/' + name
})
.then(function (res) {
console.log('Id', res.data.id);
return res.data;
});
};
var deleteAllInvitations = function () {
inject('fetchUser');
inject('promisify');
inject('fetchGithubOrgId');
inject('$state');
inject('$q');
return fetchUser()
.then(function (user) {
return $q.when(fetchGithubOrgId($state.params.userName))
.then(function (id) {
return promisify(user, 'fetchTeammateInvitations')({
orgGithubId: id
})
})
.then(function (invitations) {
return $q.all(invitations.map(function (invite) {
console.log(invite.id());
return promisify(user, 'destroyTeammateInvitation')(invite.id())
.then(() => console.log('Success'))
.catch(() => console.log('Failure'))
}));
});
});
};
var whiteListOrg = function (orgName) {
inject('configAPIHost');
inject('$http');
return $http({
url: configAPIHost + '/auth/whitelist',
method: "POST",
data: { 'name' : orgName }
})
.then(function (data) {
console.log(data);
});
};
var loginAsUser = function (accessToken) {
inject('$http')
inject('configAPIHost');
console.log('configAPIHost', configAPIHost, accessToken);
return $http.post(
configAPIHost + '/auth/github/token',
{accessToken: accessToken}
)
}
var getInstances = function (repoName, branchName) {
inject('fetchUser')
inject('$rootScope')
inject('promisify')
inject('keypather')
if (typeof repoName !== 'string') {
throw new Error('`repoName` is required');
}
return fetchUser()
.then((user) => {
var name = $rootScope.dataApp.data.activeAccount.oauthName();
return promisify(user, 'fetchInstances')({
githubUsername: name
})
})
.then((instances) => {
return instances.filter((i) => {
var acv = keypather.get(i, 'attrs.contextVersion.appCodeVersions[0]');
if (!acv) return false;
if (!branchName) return acv.lowerRepo.includes(repoName);
return (
acv.branch === branchName &&
acv.lowerRepo.includes(repoName)
)
})
})
};
var deleteInstances = function (repoName, branchName) {
inject('promisify')
inject('$q')
getInstances(repoName, branchName)
.then((instances) => {
return $q.all(
instances.map((i) => promisify(i, 'destory')())
);
})
}
You can either copy/paste the following scripts above into the console every time you want to use them, or you can use this Chrome plugin to save them permanently and bind them to a specific URL.