Merge pull request #43 from mikepenz/feature/add_repository_resolval
Resolve repo user and name
This commit is contained in:
+21
-20
@@ -301,7 +301,6 @@ const gitHelper_1 = __webpack_require__(353);
|
||||
const github = __importStar(__webpack_require__(5438));
|
||||
const configuration_1 = __webpack_require__(5527);
|
||||
function run() {
|
||||
var _a, _b, _c, _d;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.setOutput('failed', false); // mark the action not failed by default
|
||||
core.startGroup(`📘 Reading input values`);
|
||||
@@ -314,8 +313,8 @@ function run() {
|
||||
const configuration = utils_1.resolveConfiguration(repositoryPath, configurationFile);
|
||||
// read in repository inputs
|
||||
const token = core.getInput('token');
|
||||
const owner = (_a = core.getInput('owner')) !== null && _a !== void 0 ? _a : github.context.repo.owner;
|
||||
const repo = (_b = core.getInput('repo')) !== null && _b !== void 0 ? _b : github.context.repo.repo;
|
||||
const owner = core.getInput('owner') || github.context.repo.owner;
|
||||
const repo = core.getInput('repo') || github.context.repo.repo;
|
||||
// read in from, to tag inputs
|
||||
const fromTag = core.getInput('fromTag');
|
||||
let toTag = core.getInput('toTag');
|
||||
@@ -371,7 +370,9 @@ function run() {
|
||||
failOnError,
|
||||
configuration
|
||||
});
|
||||
core.setOutput('changelog', (_d = (_c = (yield releaseNotes.pull(token))) !== null && _c !== void 0 ? _c : configuration.empty_template) !== null && _d !== void 0 ? _d : configuration_1.DefaultConfiguration.empty_template);
|
||||
core.setOutput('changelog', (yield releaseNotes.pull(token)) ||
|
||||
configuration.empty_template ||
|
||||
configuration_1.DefaultConfiguration.empty_template);
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
@@ -632,7 +633,6 @@ class ReleaseNotes {
|
||||
this.options = options;
|
||||
}
|
||||
pull(token) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const octokit = new rest_1.Octokit({
|
||||
auth: `token ${token || process.env.GITHUB_TOKEN}`
|
||||
@@ -642,7 +642,8 @@ class ReleaseNotes {
|
||||
core.startGroup(`🔖 Resolve previous tag`);
|
||||
core.debug(`fromTag undefined, trying to resolve via API`);
|
||||
const tagsApi = new tags_1.Tags(octokit);
|
||||
const previousTag = yield tagsApi.findPredecessorTag(owner, repo, toTag, ignorePreReleases, (_a = configuration.max_tags_to_fetch) !== null && _a !== void 0 ? _a : configuration_1.DefaultConfiguration.max_tags_to_fetch);
|
||||
const previousTag = yield tagsApi.findPredecessorTag(owner, repo, toTag, ignorePreReleases, configuration.max_tags_to_fetch ||
|
||||
configuration_1.DefaultConfiguration.max_tags_to_fetch);
|
||||
if (previousTag == null) {
|
||||
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${toTag}`, failOnError);
|
||||
return null;
|
||||
@@ -672,7 +673,6 @@ class ReleaseNotes {
|
||||
});
|
||||
}
|
||||
getMergedPullRequests(octokit) {
|
||||
var _a, _b, _c;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { owner, repo, fromTag, toTag, failOnError, configuration } = this.options;
|
||||
core.info(`ℹ️ Comparing ${owner}/${repo} - '${fromTag}...${toTag}'`);
|
||||
@@ -693,7 +693,8 @@ class ReleaseNotes {
|
||||
const lastCommit = commits[commits.length - 1];
|
||||
let fromDate = firstCommit.date;
|
||||
const toDate = lastCommit.date;
|
||||
const maxDays = (_a = configuration.max_back_track_time_days) !== null && _a !== void 0 ? _a : configuration_1.DefaultConfiguration.max_back_track_time_days;
|
||||
const maxDays = configuration.max_back_track_time_days ||
|
||||
configuration_1.DefaultConfiguration.max_back_track_time_days;
|
||||
const maxFromDate = toDate.clone().subtract(maxDays, 'days');
|
||||
if (maxFromDate.isAfter(fromDate)) {
|
||||
core.info(`⚠️ Adjusted 'fromDate' to go max ${maxDays} back`);
|
||||
@@ -701,9 +702,10 @@ class ReleaseNotes {
|
||||
}
|
||||
core.info(`ℹ️ Fetching PRs between dates ${fromDate.toISOString()} to ${toDate.toISOString()} for ${owner}/${repo}`);
|
||||
const pullRequestsApi = new pullRequests_1.PullRequests(octokit);
|
||||
const pullRequests = yield pullRequestsApi.getBetweenDates(owner, repo, fromDate, toDate, (_b = configuration.max_pull_requests) !== null && _b !== void 0 ? _b : configuration_1.DefaultConfiguration.max_pull_requests);
|
||||
const pullRequests = yield pullRequestsApi.getBetweenDates(owner, repo, fromDate, toDate, configuration.max_pull_requests || configuration_1.DefaultConfiguration.max_pull_requests);
|
||||
core.info(`ℹ️ Retrieved ${pullRequests.length} merged PRs for ${owner}/${repo}`);
|
||||
const prCommits = pullRequestsApi.filterCommits(commits, (_c = configuration.exclude_merge_branches) !== null && _c !== void 0 ? _c : configuration_1.DefaultConfiguration.exclude_merge_branches);
|
||||
const prCommits = pullRequestsApi.filterCommits(commits, configuration.exclude_merge_branches ||
|
||||
configuration_1.DefaultConfiguration.exclude_merge_branches);
|
||||
core.info(`ℹ️ Retrieved ${prCommits.length} PR merge commits for ${owner}/${repo}`);
|
||||
const filteredPullRequests = [];
|
||||
const pullRequestsByNumber = {};
|
||||
@@ -921,9 +923,8 @@ const pullRequests_1 = __webpack_require__(4217);
|
||||
const core = __importStar(__webpack_require__(2186));
|
||||
const configuration_1 = __webpack_require__(5527);
|
||||
function buildChangelog(prs, config) {
|
||||
var _a, _b, _c;
|
||||
// sort to target order
|
||||
const sort = (_a = config.sort) !== null && _a !== void 0 ? _a : configuration_1.DefaultConfiguration.sort;
|
||||
const sort = config.sort || configuration_1.DefaultConfiguration.sort;
|
||||
const sortAsc = sort.toUpperCase() === 'ASC';
|
||||
prs = pullRequests_1.sortPullRequests(prs, sortAsc);
|
||||
core.info(`ℹ️ Sorted all pull requests ascending: ${sort}`);
|
||||
@@ -939,7 +940,7 @@ function buildChangelog(prs, config) {
|
||||
core.info(`✒️ Wrote messages for ${prs.length} pull requests`);
|
||||
// bring PRs into the order of categories
|
||||
const categorized = new Map();
|
||||
const categories = (_b = config.categories) !== null && _b !== void 0 ? _b : configuration_1.DefaultConfiguration.categories;
|
||||
const categories = config.categories || configuration_1.DefaultConfiguration.categories;
|
||||
for (const category of categories) {
|
||||
categorized.set(category, []);
|
||||
}
|
||||
@@ -977,7 +978,7 @@ function buildChangelog(prs, config) {
|
||||
}
|
||||
core.info(`✒️ Wrote ${changelogUncategorized.length} non categorized pull requests down`);
|
||||
// fill template
|
||||
let transformedChangelog = (_c = config.template) !== null && _c !== void 0 ? _c : configuration_1.DefaultConfiguration.template;
|
||||
let transformedChangelog = config.template || configuration_1.DefaultConfiguration.template;
|
||||
transformedChangelog = transformedChangelog.replace('${{CHANGELOG}}', changelog);
|
||||
transformedChangelog = transformedChangelog.replace('${{UNCATEGORIZED}}', changelogUncategorized);
|
||||
core.info(`ℹ️ Filled template`);
|
||||
@@ -988,18 +989,18 @@ function haveCommonElements(arr1, arr2) {
|
||||
return arr1.some(item => arr2.includes(item));
|
||||
}
|
||||
function fillTemplate(pr, template) {
|
||||
var _a, _b, _c, _d, _e, _f, _g;
|
||||
var _a, _b, _c;
|
||||
let transformed = template;
|
||||
transformed = transformed.replace('${{NUMBER}}', pr.number.toString());
|
||||
transformed = transformed.replace('${{TITLE}}', pr.title);
|
||||
transformed = transformed.replace('${{URL}}', pr.htmlURL);
|
||||
transformed = transformed.replace('${{MERGED_AT}}', pr.mergedAt.toISOString());
|
||||
transformed = transformed.replace('${{AUTHOR}}', pr.author);
|
||||
transformed = transformed.replace('${{LABELS}}', (_b = (_a = pr.labels) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : '');
|
||||
transformed = transformed.replace('${{MILESTONE}}', (_c = pr.milestone) !== null && _c !== void 0 ? _c : '');
|
||||
transformed = transformed.replace('${{LABELS}}', ((_a = pr.labels) === null || _a === void 0 ? void 0 : _a.join(', ')) || '');
|
||||
transformed = transformed.replace('${{MILESTONE}}', pr.milestone || '');
|
||||
transformed = transformed.replace('${{BODY}}', pr.body);
|
||||
transformed = transformed.replace('${{ASSIGNEES}}', (_e = (_d = pr.assignees) === null || _d === void 0 ? void 0 : _d.join(', ')) !== null && _e !== void 0 ? _e : '');
|
||||
transformed = transformed.replace('${{REVIEWERS}}', (_g = (_f = pr.requestedReviewers) === null || _f === void 0 ? void 0 : _f.join(', ')) !== null && _g !== void 0 ? _g : '');
|
||||
transformed = transformed.replace('${{ASSIGNEES}}', ((_b = pr.assignees) === null || _b === void 0 ? void 0 : _b.join(', ')) || '');
|
||||
transformed = transformed.replace('${{REVIEWERS}}', ((_c = pr.requestedReviewers) === null || _c === void 0 ? void 0 : _c.join(', ')) || '');
|
||||
return transformed;
|
||||
}
|
||||
function transform(filled, transformers) {
|
||||
@@ -1013,7 +1014,7 @@ function transform(filled, transformers) {
|
||||
return transformed;
|
||||
}
|
||||
function validateTransfomers(specifiedTransformers) {
|
||||
const transformers = specifiedTransformers !== null && specifiedTransformers !== void 0 ? specifiedTransformers : configuration_1.DefaultConfiguration.transformers;
|
||||
const transformers = specifiedTransformers || configuration_1.DefaultConfiguration.transformers;
|
||||
return transformers
|
||||
.map(transformer => {
|
||||
try {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
@@ -27,8 +27,8 @@ async function run(): Promise<void> {
|
||||
|
||||
// read in repository inputs
|
||||
const token = core.getInput('token')
|
||||
const owner = core.getInput('owner') ?? github.context.repo.owner
|
||||
const repo = core.getInput('repo') ?? github.context.repo.repo
|
||||
const owner = core.getInput('owner') || github.context.repo.owner
|
||||
const repo = core.getInput('repo') || github.context.repo.repo
|
||||
// read in from, to tag inputs
|
||||
const fromTag = core.getInput('fromTag')
|
||||
let toTag = core.getInput('toTag')
|
||||
@@ -92,8 +92,8 @@ async function run(): Promise<void> {
|
||||
|
||||
core.setOutput(
|
||||
'changelog',
|
||||
(await releaseNotes.pull(token)) ??
|
||||
configuration.empty_template ??
|
||||
(await releaseNotes.pull(token)) ||
|
||||
configuration.empty_template ||
|
||||
DefaultConfiguration.empty_template
|
||||
)
|
||||
} catch (error) {
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ export class ReleaseNotes {
|
||||
repo,
|
||||
toTag,
|
||||
ignorePreReleases,
|
||||
configuration.max_tags_to_fetch ??
|
||||
configuration.max_tags_to_fetch ||
|
||||
DefaultConfiguration.max_tags_to_fetch
|
||||
)
|
||||
if (previousTag == null) {
|
||||
@@ -116,7 +116,7 @@ export class ReleaseNotes {
|
||||
const toDate = lastCommit.date
|
||||
|
||||
const maxDays =
|
||||
configuration.max_back_track_time_days ??
|
||||
configuration.max_back_track_time_days ||
|
||||
DefaultConfiguration.max_back_track_time_days
|
||||
const maxFromDate = toDate.clone().subtract(maxDays, 'days')
|
||||
if (maxFromDate.isAfter(fromDate)) {
|
||||
@@ -134,7 +134,7 @@ export class ReleaseNotes {
|
||||
repo,
|
||||
fromDate,
|
||||
toDate,
|
||||
configuration.max_pull_requests ?? DefaultConfiguration.max_pull_requests
|
||||
configuration.max_pull_requests || DefaultConfiguration.max_pull_requests
|
||||
)
|
||||
|
||||
core.info(
|
||||
@@ -143,7 +143,7 @@ export class ReleaseNotes {
|
||||
|
||||
const prCommits = pullRequestsApi.filterCommits(
|
||||
commits,
|
||||
configuration.exclude_merge_branches ??
|
||||
configuration.exclude_merge_branches ||
|
||||
DefaultConfiguration.exclude_merge_branches
|
||||
)
|
||||
|
||||
|
||||
+8
-8
@@ -12,7 +12,7 @@ export function buildChangelog(
|
||||
config: Configuration
|
||||
): string {
|
||||
// sort to target order
|
||||
const sort = config.sort ?? DefaultConfiguration.sort
|
||||
const sort = config.sort || DefaultConfiguration.sort
|
||||
const sortAsc = sort.toUpperCase() === 'ASC'
|
||||
prs = sortPullRequests(prs, sortAsc)
|
||||
core.info(`ℹ️ Sorted all pull requests ascending: ${sort}`)
|
||||
@@ -41,7 +41,7 @@ export function buildChangelog(
|
||||
|
||||
// bring PRs into the order of categories
|
||||
const categorized = new Map<Category, string[]>()
|
||||
const categories = config.categories ?? DefaultConfiguration.categories
|
||||
const categories = config.categories || DefaultConfiguration.categories
|
||||
for (const category of categories) {
|
||||
categorized.set(category, [])
|
||||
}
|
||||
@@ -89,7 +89,7 @@ export function buildChangelog(
|
||||
)
|
||||
|
||||
// fill template
|
||||
let transformedChangelog = config.template ?? DefaultConfiguration.template
|
||||
let transformedChangelog = config.template || DefaultConfiguration.template
|
||||
transformedChangelog = transformedChangelog.replace(
|
||||
'${{CHANGELOG}}',
|
||||
changelog
|
||||
@@ -113,16 +113,16 @@ function fillTemplate(pr: PullRequestInfo, template: string): string {
|
||||
transformed = transformed.replace('${{URL}}', pr.htmlURL)
|
||||
transformed = transformed.replace('${{MERGED_AT}}', pr.mergedAt.toISOString())
|
||||
transformed = transformed.replace('${{AUTHOR}}', pr.author)
|
||||
transformed = transformed.replace('${{LABELS}}', pr.labels?.join(', ') ?? '')
|
||||
transformed = transformed.replace('${{MILESTONE}}', pr.milestone ?? '')
|
||||
transformed = transformed.replace('${{LABELS}}', pr.labels?.join(', ') || '')
|
||||
transformed = transformed.replace('${{MILESTONE}}', pr.milestone || '')
|
||||
transformed = transformed.replace('${{BODY}}', pr.body)
|
||||
transformed = transformed.replace(
|
||||
'${{ASSIGNEES}}',
|
||||
pr.assignees?.join(', ') ?? ''
|
||||
pr.assignees?.join(', ') || ''
|
||||
)
|
||||
transformed = transformed.replace(
|
||||
'${{REVIEWERS}}',
|
||||
pr.requestedReviewers?.join(', ') ?? ''
|
||||
pr.requestedReviewers?.join(', ') || ''
|
||||
)
|
||||
return transformed
|
||||
}
|
||||
@@ -142,7 +142,7 @@ function validateTransfomers(
|
||||
specifiedTransformers: Transformer[]
|
||||
): RegexTransformer[] {
|
||||
const transformers =
|
||||
specifiedTransformers ?? DefaultConfiguration.transformers
|
||||
specifiedTransformers || DefaultConfiguration.transformers
|
||||
return transformers
|
||||
.map(transformer => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user