How to use the @atomist/sdm.toToken function in @atomist/sdm

To help you get started, we’ve selected a few @atomist/sdm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export function tipOfDefaultBranch(creds: string | ProjectOperationCredentials, rr: GitHubRepoRef): Promise {
    // TODO: use real default branch
    const config = authHeaders(toToken(creds));
    const url = `${rr.scheme}${rr.apiBase}/repos/${rr.owner}/${rr.repo}/branches/master`;
    return axios.get(url, config)
        .then(ap => ap.data.commit.sha);
}
github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export function updateIssue(creds: string | ProjectOperationCredentials,
                            rr: RemoteRepoRef,
                            issueNumber: number,
                            issue: Issue): AxiosPromise {
    const grr = isGitHubRepoRef(rr) ? rr : new GitHubRepoRef(rr.owner, rr.repo, rr.sha);
    const url = `${grr.scheme}${grr.apiBase}/repos/${grr.owner}/${grr.repo}/issues/${issueNumber}`;
    logger.debug(`Request to '${url}' to update issue`);
    return axios.patch(url, issue, authHeaders(toToken(creds)));
}
github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export function createTagReference(creds: string | ProjectOperationCredentials, rr: GitHubRepoRef, tag: Tag): AxiosPromise {
    const config = authHeaders(toToken(creds));
    const url = `${rr.scheme}${rr.apiBase}/repos/${rr.owner}/${rr.repo}/git/refs`;
    logger.debug("Creating github reference: %s to %j", url, tag);
    return doWithRetry(() => axios.post(url, { ref: `refs/tags/${tag.tag}`, sha: tag.object }, config)
        .catch(err =>
            Promise.reject(new Error(`Error hitting ${url} to set tag ${JSON.stringify(tag)}: ${err.message}`)),
        ), `Updating github tag: ${url} to ${JSON.stringify(tag)}`, {});
}
github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export function createTag(creds: string | ProjectOperationCredentials, rr: GitHubRepoRef, tag: Tag): AxiosPromise {
    const config = authHeaders(toToken(creds));
    const url = `${rr.scheme}${rr.apiBase}/repos/${rr.owner}/${rr.repo}/git/tags`;
    logger.debug("Updating github tag: %s to %j", url, tag);
    return doWithRetry(() => axios.post(url, tag, config)
        .catch(err =>
            Promise.reject(new Error(`Error hitting ${url} to set tag ${JSON.stringify(tag)}: ${err.message}`)),
        ), `Updating github tag: ${url} to ${JSON.stringify(tag)}`, {});
}
github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export function isPublicRepo(creds: string | ProjectOperationCredentials, rr: GitHubRepoRef): Promise {
    const config = authHeaders(toToken(creds));
    const url = `${rr.scheme}${rr.apiBase}/repos/${rr.owner}/${rr.repo}`;
    return axios.get(url, config)
        .then(ap => {
            const privateness = ap.data.private;
            logger.debug(`Retrieved ${url}. Private is '${privateness}'`);
            return !privateness;
        })
        .catch(err => {
            logger.warn(`Could not access ${url} to determine repo visibility: ${err.message}`);
            return false;
        });
}
github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export function deleteRepository(creds: string | ProjectOperationCredentials, rr: GitHubRepoRef): AxiosPromise {
    const config = authHeaders(toToken(creds));
    const url = `${rr.scheme}${rr.apiBase}/repos/${rr.owner}/${rr.repo}`;
    logger.debug("Deleting repository: %s", url);
    return axios.delete(url, config)
        .catch(err => {
            logger.error(err.message);
            logger.error(err.response.body);
            return Promise.reject(new Error(`Error hitting ${url} to delete repo`));
        },
        );
}
github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export async function listTopics(creds: string | ProjectOperationCredentials, rr: RemoteRepoRef): Promise {
    const headers = {
        headers: {
            ...authHeaders(toToken(creds)).headers,
            Accept: "application/vnd.github.mercy-preview+json",
        },
    };
    const grr = isGitHubRepoRef(rr) ? rr : new GitHubRepoRef(rr.owner, rr.repo, rr.sha);
    const url = `${grr.scheme}${grr.apiBase}/repos/${grr.owner}/${grr.repo}/topics`;
    const topics = await axios.get(url, headers);
    return topics.data.names;
}
github atomist / sdm-core / lib / util / github / gitHubTagRouter.ts View on Github external
export const GitHubTagRouter: TagRouter = async (tags, params) => {
    const grr = isGitHubRepoRef(tags.repoId) ? tags.repoId : new GitHubRepoRef(tags.repoId.owner, tags.repoId.repo, tags.repoId.sha);
    const url = `${grr.scheme}${grr.apiBase}/repos/${grr.owner}/${grr.repo}/topics`;
    const names = _.uniq(tags.tags);
    const httpClient = configurationValue("http.client.factory", defaultHttpClientFactory()).create();
    logger.debug(`Request to '${url}' to raise tags: [${names.join()}]`);
    try {
        await httpClient.exchange(url, {
            body: { names },
            headers: {
                ...authHeaders(toToken(params.targets.credentials)).headers,
                Accept: "application/vnd.github.mercy-preview+json",
            },
            method: HttpMethod.Put,
        });
    } catch (e) {
        e.message = `Failed to create GitHub topics '${names.join()}' on '${url}': ${e.message}`;
        logger.error(e.message);
        throw e;
    }
    return successOn(tags);
};
github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export function createRelease(creds: string | ProjectOperationCredentials, rr: GitHubRepoRef, release: Release): AxiosPromise {
    const config = authHeaders(toToken(creds));
    const url = `${rr.scheme}${rr.apiBase}/repos/${rr.owner}/${rr.repo}/releases`;
    logger.debug("Updating github release: %s to %j", url, release);
    return doWithRetry(() => axios.post(url, release, config)
        .catch(err =>
            Promise.reject(new Error(`Error hitting ${url} to set release ${JSON.stringify(release)}: ${err.message}`)),
        ), `Updating github release: ${url} to ${JSON.stringify(release)}`, {});
}
github atomist / sdm-core / lib / util / github / ghub.ts View on Github external
export function listCommitsBetween(creds: string | ProjectOperationCredentials,
                                   rr: GitHubRepoRef,
                                   startSha: string,
                                   endSha: string): Promise {
    const config = authHeaders(toToken(creds));
    const url = `${rr.scheme}${rr.apiBase}/repos/${rr.owner}/${rr.repo}/compare/${startSha}...${endSha}`;
    return axios.get(url, config)
        .then(ap => ap.data);
}