Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async addCommentUsingSubjectId(pullRequestId: GraphQlQueryResponseData, comment: string) {
console.log(`pullRequestId ===>>>> ${pullRequestId}`)
let data = JSON.parse(JSON.stringify(pullRequestId));
console.log(`Parsed pull request id ${data}`)
const token = core.getInput('repo-token');
let graphQlResponse = graphql(this.addPullRequestCommentMutation(), {
headers: {
authorization: `token ${token}`,
},
subjectId: data.repository.pullRequest.id,
body: comment,
},
);
console.log(`Adding the comment ...`);
return await graphQlResponse;
}
private async getSubjectId(findPullRequestIdQuery: string, nameAndRepo: string[]) {
console.log('Inside getSubjectId');
const token = core.getInput('repo-token');
let newVar: GraphQlQueryResponseData = await graphql(findPullRequestIdQuery, {
headers: {
authorization: `token ${token}`,
},
owner: nameAndRepo[0],
repo: nameAndRepo[1],
pullNumber: this.getPullNumber(),
},
);
console.log(`Exiting getSubject Id`);
return newVar;
}
const buildContributorInfo = async (contributors: WeightedContributor[]): Promise => {
const query = `{
${contributors.map((c, i) => `user${i}: user(login: "${c.login}") {...UserFragment}`).join(`\n`)}
}
fragment UserFragment on User {
login
name
websiteUrl
avatarUrl
}`
try {
const resp = await graphql.graphql(query, {
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`,
},
})
return contributors.map((_, i) => resp[`user${i}`]).filter((v) => v)
} catch (err) {
if (err.errors && err.data) {
console.warn(`github errors:`, err.errors)
return contributors.map((_, i) => err.data[`user${i}`]).filter((v) => v)
}
throw err
}
}
return __awaiter(this, void 0, void 0, function* () {
console.log('Inside getSubjectId');
const token = core.getInput('repo-token');
let newVar = yield graphql_1.graphql(findPullRequestIdQuery, {
headers: {
authorization: `token ${token}`,
},
owner: nameAndRepo[0],
repo: nameAndRepo[1],
pullNumber: this.getPullNumber(),
});
console.log(`Exiting getSubject Id`);
return newVar;
});
}
return __awaiter(this, void 0, void 0, function* () {
console.log(`pullRequestId ===>>>> ${pullRequestId}`);
let data = JSON.parse(JSON.stringify(pullRequestId));
console.log(`Parsed pull request id ${data}`);
const token = core.getInput('repo-token');
let graphQlResponse = graphql_1.graphql(this.addPullRequestCommentMutation(), {
headers: {
authorization: `token ${token}`,
},
subjectId: data.repository.pullRequest.id,
body: comment,
});
console.log(`Adding the comment ...`);
return yield graphQlResponse;
});
}
async graphql(query: string) {
this.logger.verbose.info('Querying Github using GraphQL:\n', query);
const data = await graphql(query, {
baseUrl: this.graphqlBaseUrl,
headers: {
authorization: `token ${this.options.token}`
}
});
this.logger.veryVerbose.info('Got response from query\n', data);
return data;
}
async function main() {
const { endpoints } = await graphql(QUERY, {
url: "https://octokit-routes-graphql-server.now.sh/",
version: process.env.VERSION
});
writeFileSync(
path.resolve(__dirname, "generated", "endpoints.json"),
prettier.format(JSON.stringify(endpoints), {
parser: "json"
})
);
}
private async getSubjectId(findPullRequestIdQuery: string, nameAndRepo: string[]) {
core.debug('Inside getSubjectId');
const token = core.getInput('repo-token');
let newVar: GraphQlQueryResponseData = await graphql(findPullRequestIdQuery, {
headers: {
authorization: `token ${token}`,
},
owner: nameAndRepo[0],
repo: nameAndRepo[1],
pullNumber: this.getPullNumber(),
},
);
core.debug(`Exiting getSubject Id`);
return newVar;
}
async function main () {
const { endpoints } = await graphql(QUERY, {
url: 'https://octokit-routes-graphql-server.now.sh/',
version: process.env.VERSION
})
writeFileSync(
path.resolve(__dirname, 'generated', 'endpoints.json'),
JSON.stringify(endpoints, null, 2) + '\n'
)
}