Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
config: {
getTagName: () => 'v1.2.3',
releases: { assetsToUpload, extractChangelog },
updateChangelog: false,
},
dir: '.',
dryRun: false,
});
const createRelease = jest.fn().mockImplementation(() => ({
data: {
upload_url: 'https://dummy/upload/url', // eslint-disable-line camelcase
},
}));
const uploadReleaseAsset = jest.fn();
Octokit.mockImplementation(function() {
this.repos = { createRelease, uploadReleaseAsset };
});
describe('createGitHubRelease', () => {
beforeEach(() => {
getRepoInfo.mockImplementation(() => ({
owner: 'my',
name: 'repo',
}));
fs.readFileSync = jest.fn();
fs.statSync = jest.fn().mockImplementation(() => ({ size: 1024 }));
mime.lookup.mockImplementation(() => 'application/zip');
globby.mockImplementation(path => Promise.resolve([path]));
});
it('works without assets', async () => {
it('returns pr url', async () => {
const create = jest.fn().mockImplementationOnce(() => ({
data: { number: 13, html_url: 'https://github.com/my/repo/pull/13' }, // eslint-disable-line camelcase
}));
Octokit.mockImplementationOnce(function() {
this.pulls = { create, createReviewRequest: jest.fn() };
});
const { pullRequestUrl } = await createPullRequest(getDefaultParams());
expect(pullRequestUrl).toEqual('https://github.com/my/repo/pull/13');
});
github_user: user,
api: { protocol, pathPrefix, host },
} = config
const isEnterprise = host !== 'api.github.com'
const apiUrl = `${protocol}://${isEnterprise ? host : 'api.github.com'}`
const { href } = new URL(`${apiUrl}${pathPrefix || ''}`)
// trim trailing slash for Octokit
const baseUrl = href.replace(/\/+$/, '')
const throttlePlugin = await import('@octokit/plugin-throttling')
Octokit.plugin(throttlePlugin)
return new Octokit({
// log: console,
baseUrl,
auth: await getToken({ token, user }),
throttle: {
onRateLimit: (retryAfter, options) => {
console.warn(`Request quota exhausted for request ${options.method} ${options.url}`)
if (options.request.retryCount === 0) {
// only retries once
console.log(`Retrying after ${retryAfter} seconds!`)
return true
}
},
onAbuseLimit: (_, options) => {
function getOctokit(): any {
if (cachedOctokit) {
return cachedOctokit;
}
const Octokit = require('@octokit/rest').plugin(
require('@octokit/plugin-throttling'),
);
return (cachedOctokit = new Octokit({
auth: GITHUB_TOKEN,
throttle: {
onRateLimit: (retryAfter: number, options: any) => {
console.warn(
`Request quota exhausted for request ${options.method} ${
options.url
}`,
);
// retries 3 times
if (options.request.retryCount < 3) {
console.log(`Retrying after ${retryAfter} seconds!`);
return true;
}
private initializeOctokit(): Octokit {
return new Octokit({
auth: config.githubAuthToken,
userAgent: config.githubUsername,
// Comment this block and uncomment lower block for debugging
// WARNING: ADDITIONAL INFO INCLUDES PERSONAL ACCESS TOKEN
log: {
debug: (message: any, info?: any) => log('debug', `Message: ${message}` ),
info: (message: any, info?: any) => log('info', `Message: ${message}}` ),
warn: (message: any, info?: any) => log('info', `Message: ${message}` ),
error: (message: any, info?: any) => log('info', `Message: ${message}` )
}
/*log: {
debug: (message: any, info?: any) => log('debug', `Message: ${message}, Additional Info: ${info ? JSON.stringify(info) : 'No additional Info'}` ),
info: (message: any, info?: any) => log('info', `Message: ${message}, Additional Info: ${info ? JSON.stringify(info) : 'No additional Info'}` ),
warn: (message: any, info?: any) => log('info', `Message: ${message}, Additional Info: ${info ? JSON.stringify(info) : 'No additional Info'}` ),
error: (message: any, info?: any) => log('info', `Message: ${message}, Additional Info: ${info ? JSON.stringify(info) : 'No additional Info'}` )
}*/
import Octokit from "@octokit/rest";
import { GitHubApi } from "./api";
const ThrottledOctokit = Octokit.plugin(require("@octokit/plugin-throttling"));
interface ThrottlingOptions {
method: string;
url: string;
request: {
retryCount: number;
};
}
export function buildGitHubApi(token: string): GitHubApi {
const octokit = new ThrottledOctokit({
auth: `token ${token}`,
// https://developer.github.com/v3/pulls/#list-pull-requests
// Enable Draft Pull Request API.
previews: ["shadow-cat"],
throttle: {
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const tl = require('azure-pipelines-task-lib/task');
const util = require('./util');
const { Octokit } = require("@octokit/rest");
const OWNER = 'microsoft';
const REPO = 'azure-pipelines-agent';
const GIT = 'git';
const VALID_RELEASE_RE = /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/;
const octokit = new Octokit({}); // only read-only operations, no need to auth
process.env.EDITOR = process.env.EDITOR === undefined ? 'code --wait' : process.env.EDITOR;
var opt = require('node-getopt').create([
['', 'dryrun', 'Dry run only, do not actually commit new release'],
['', 'derivedFrom=version', 'Used to get PRs merged since this release was created', 'latest'],
['', 'branch=branch', 'Branch to select PRs merged into', 'master'],
['h', 'help', 'Display this help'],
])
.setHelp(
'Usage: node createReleaseBranch.js [OPTION] \n' +
'\n' +
'[[OPTIONS]]\n'
)
.bindHelp() // bind option 'help' to default action
.parseSystem(); // parse command line
const fs = require('fs');
const cp = require('child_process');
const naturalSort = require('natural-sort');
const path = require('path');
const { Octokit } = require("@octokit/rest");
const owner = 'microsoft';
const repo = 'azure-pipelines-agent';
const octokit = new Octokit({}); // only read-only operations, no need to auth
const INTEGRATION_DIR = path.join(__dirname, '..', '_layout', 'integrations');
const GIT = 'git';
const VALID_RELEASE_RE = /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/;
const GIT_RELEASE_RE = /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/;
process.env.EDITOR = process.env.EDITOR === undefined ? 'code --wait' : process.env.EDITOR;
var opt = require('node-getopt').create([
['', 'dryrun', 'Dry run only, do not actually commit new release'],
['', 'unattended', 'This is run in a pipeline, so do not prompt for confirmation of release notes'],
['', 'derivedFrom=version', 'Used to get PRs merged since this release was created', 'latest'],
['', 'branch=branch', 'Branch to select PRs merged into', 'master'],
['h', 'help', 'Display this help'],
])
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/github.ts
const graphql_1 = require("@octokit/graphql");
const rest_1 = require("@octokit/rest");
const Context = __importStar(require("./context"));
const httpClient = __importStar(require("@actions/http-client"));
// We need this in order to extend Octokit
rest_1.Octokit.prototype = new rest_1.Octokit();
exports.context = new Context.Context();
class GitHub extends rest_1.Octokit {
constructor(token, opts) {
super(GitHub.getOctokitOptions(GitHub.disambiguate(token, opts)));
this.graphql = GitHub.getGraphQL(GitHub.disambiguate(token, opts));
}
/**
* Disambiguates the constructor overload parameters
*/
static disambiguate(token, opts) {
return [
typeof token === 'string' ? token : '',
typeof token === 'object' ? token : opts || {}
];
}
static getOctokitOptions(args) {
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/github.ts
import {graphql} from '@octokit/graphql'
// we need this type to set up a property on the GitHub object
// that has token authorization
// (it is not exported from octokit by default)
import {graphql as GraphQL} from '@octokit/graphql/dist-types/types'
import Octokit from '@octokit/rest'
import * as Context from './context'
// We need this in order to extend Octokit
Octokit.prototype = new Octokit()
export const context = new Context.Context()
export class GitHub extends Octokit {
graphql: GraphQL
constructor(token: string, opts: Omit = {}) {
super({...opts, auth: `token ${token}`})
this.graphql = graphql.defaults({
headers: {authorization: `token ${token}`}
})
}
}