Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions src/common/github-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,6 @@ interface ExtractDeployedShaParams extends ServerlessGitOpsParams {
gitOpsSha: string;
}

const SEMVER_REGEX = /^v(\d+)\.(\d+)\.(\d+)$/;

function filterPrsForVersion(
prs: PrItem[],
version: string,
ignoredVersionLabels: readonly string[] = []
): PrItem[] {
return prs.filter((pr) => {
const prVersions = pr.labels
.filter((label) => label.name?.match(SEMVER_REGEX))
.filter((label) => label.name && !ignoredVersionLabels.includes(label.name))
.map((label) => semver.clean(label.name ?? '') ?? '');
// Check if there is any version label below the one we are looking for
// which would mean this PR has already been released (and blogged about)
// in an earlier dev documentation blog post.
return !prVersions.some((verLabel) => semver.lt(verLabel, version));
});
}

export class GitHubService {
private octokit: Octokit;
private repoId: number | undefined;
Expand Down Expand Up @@ -231,15 +212,13 @@ export class GitHubService {
const options = this.octokit.search.issuesAndPullRequests.endpoint.merge({
q: `repo:${GITHUB_OWNER}/${this.repoName} label:release_note:plugin_api_changes label:${version}`,
});
const items = await this.octokit.paginate<PrItem>(options);
return filterPrsForVersion(items, version);
return await this.octokit.paginate<PrItem>(options);
}

public async getPrsForVersion(
version: string,
excludedLabels: readonly string[] = [],
includedLabels: readonly string[] = [],
ignoredVersionLabels: readonly string[] = []
includedLabels: readonly string[] = []
): Promise<Observable<Progress<PrItem>>> {
const semVer = semver.parse(version);

Expand Down Expand Up @@ -281,7 +260,7 @@ export class GitHubService {
(async () => {
const items: PrItem[] = [];
for await (const response of this.octokit.paginate.iterator<PrItem>(options)) {
items.push(...filterPrsForVersion(response.data, version, ignoredVersionLabels));
items.push(...response.data);
if (response.headers.link) {
const links = parseLinkHeader(response.headers.link);
if (links?.last?.page) {
Expand Down
53 changes: 52 additions & 1 deletion src/common/pr-utils/extracting.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { PrItem } from '../github-service';
import { normalizeTitle, findReleaseNote, extractReleaseNotes } from './extracting';
import {
normalizeTitle,
findReleaseNote,
extractReleaseNotes,
hasDuplicatePatchLabels,
} from './extracting';

describe('extraction tools', () => {
describe('normalizeTitle', () => {
Expand Down Expand Up @@ -142,4 +147,50 @@ Next paragraph
expect(actual.title).toBe('Adds cool feature in *TSVB*');
});
});

describe('hasDuplicatePatchLabels', () => {
it('should return false for invalid or missing target versions', () => {
const labels = [{ name: '8.12.0' }, { name: '8.12.1' }];

expect(hasDuplicatePatchLabels(labels, undefined)).toBe(false);
expect(hasDuplicatePatchLabels(labels, 'invalid-version')).toBe(false);
});

it('should return false when there are no matching labels', () => {
expect(hasDuplicatePatchLabels([{ name: '7.11.0' }, { name: '8.11.1' }], '8.12.0')).toBe(
false
);
});

it('should return false when there is only one matching label', () => {
expect(hasDuplicatePatchLabels([{ name: '8.12.0' }, { name: '7.11.1' }], '8.12.0')).toBe(
false
);
});

it('should return true when there are multiple matching patch labels', () => {
expect(hasDuplicatePatchLabels([{ name: '8.12.5' }, { name: '8.12.9' }], '8.12.0')).toBe(
true
);
});

it('should handle invalid and undefined label names correctly', () => {
expect(
hasDuplicatePatchLabels(
[
{ name: '8.12.0' },
{ name: 'bug' },
{ name: '8.12.1' },
{ name: 'feature' },
{ name: undefined },
],
'8.12.0'
)
).toBe(true);
});

it('should handle empty array of labels correctly', () => {
expect(hasDuplicatePatchLabels([], '8.12.0')).toBe(false);
});
});
});
33 changes: 33 additions & 0 deletions src/common/pr-utils/extracting.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Config } from '../../config';
import { PrItem } from '../github-service';
import semver from 'semver';

export type NormalizeOptions = Config['areas'][number]['options'];

Expand Down Expand Up @@ -117,3 +118,35 @@ export function extractReleaseNotes(
originalTitle: pr.title,
};
}

/**
* Checks if a PR has multiple patch version labels for the same major.minor version.
* This indicates the PR may have been documented in multiple patch releases.
*/
export function hasDuplicatePatchLabels(
prLabels: PrItem['labels'],
targetVersion: string | undefined
): boolean {
const targetSemVer = semver.parse(targetVersion);
if (!targetSemVer) {
return false;
}

// Find all version labels that match the same major.minor as target
const sameMajorMinor = prLabels.reduce<number>((acc, { name }) => {
const ver = semver.parse(name ?? '');

if (ver === null) {
return acc;
}

// tilde matches exactly on major.minor but allows for any patch version
if (semver.intersects(`~${ver.version}`, `~${targetSemVer.version}`)) {
acc++;
}

return acc;
}, 0);

return sameMajorMinor >= 2;
}
2 changes: 1 addition & 1 deletion src/common/pr-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './grouping';
export { extractReleaseNotes } from './extracting';
export { extractReleaseNotes, hasDuplicatePatchLabels } from './extracting';
export type { NormalizeOptions, ReleaseNoteDetails } from './extracting';
22 changes: 20 additions & 2 deletions src/common/pr.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import { EuiLink, EuiIconTip } from '@elastic/eui';
import { FC, memo } from 'react';
import { PrItem } from './github-service';
import { extractReleaseNotes, NormalizeOptions, ReleaseNoteDetails } from './pr-utils';
import {
extractReleaseNotes,
NormalizeOptions,
ReleaseNoteDetails,
hasDuplicatePatchLabels,
} from './pr-utils';

interface PrProps {
pr: PrItem;
showAuthor?: boolean;
showTransformedTitle?: boolean;
normalizeOptions?: NormalizeOptions;
version?: string;
}

export const Pr: FC<PrProps> = memo(
({ pr, showAuthor, showTransformedTitle, normalizeOptions }) => {
({ pr, showAuthor, showTransformedTitle, normalizeOptions, version }) => {
const title: ReleaseNoteDetails = showTransformedTitle
? extractReleaseNotes(pr, normalizeOptions)
: { type: 'title', title: pr.title };
const hasDuplicates = hasDuplicatePatchLabels(pr.labels, version);
const majorMinorVersion =
version?.substring(0, version?.lastIndexOf('.')) ?? 'this major and minor version';

return (
<>
{title.title} (
Expand All @@ -27,6 +37,14 @@ export const Pr: FC<PrProps> = memo(
</>
)}
){' '}
{hasDuplicates && (
<EuiIconTip
color="warning"
type="alert"
size="m"
content={`This PR has multiple patch version labels for ${majorMinorVersion} and may have already been documented in a previous patch release.`}
/>
)}
{title.type === 'releaseNoteTitle' && (
<EuiIconTip
color="secondary"
Expand Down
10 changes: 8 additions & 2 deletions src/pages/release-notes/components/grouped-pr-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ interface Props {
groupedPrs: { [group: string]: PrItem[] };
groups: Config['areas'];
keyPrefix: string;
version: string;
}

export const GroupedPrList: FC<Props> = memo(({ groupedPrs, groups, keyPrefix }) => {
export const GroupedPrList: FC<Props> = memo(({ groupedPrs, groups, keyPrefix, version }) => {
const sortedGroups = useMemo(
() => [...groups].sort((a, b) => a.title.localeCompare(b.title)),
[groups]
Expand Down Expand Up @@ -37,7 +38,12 @@ export const GroupedPrList: FC<Props> = memo(({ groupedPrs, groups, keyPrefix })
<ul>
{prs.map((pr) => (
<li key={pr.id}>
<Pr pr={pr} showTransformedTitle={true} normalizeOptions={group.options} />
<Pr
pr={pr}
showTransformedTitle={true}
normalizeOptions={group.options}
version={version}
/>
</li>
))}
</ul>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/release-notes/components/uncategorized-pr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { setConfig, useActiveConfig } from '../../../config';

interface UncategorizedPrProps {
pr: PrItem;
version: string;
}

const LabelBadge: FC<{ label: Label }> = memo(({ label }) => {
Expand Down Expand Up @@ -83,7 +84,7 @@ const LabelBadge: FC<{ label: Label }> = memo(({ label }) => {
);
});

export const UncategorizedPr: FC<UncategorizedPrProps> = memo(({ pr }) => {
export const UncategorizedPr: FC<UncategorizedPrProps> = memo(({ pr, version }) => {
// We only want to show non version non release_note labels in the UI
const filteredLables = useMemo(
() =>
Expand All @@ -95,7 +96,7 @@ export const UncategorizedPr: FC<UncategorizedPrProps> = memo(({ pr }) => {
return (
<EuiSplitPanel.Outer>
<EuiSplitPanel.Inner paddingSize="s">
<Pr pr={pr} showAuthor={true} />
<Pr pr={pr} showAuthor={true} version={version} />
</EuiSplitPanel.Inner>
<EuiSplitPanel.Inner paddingSize="s" color="subdued">
{filteredLables.length > 0 && (
Expand Down
5 changes: 1 addition & 4 deletions src/pages/release-notes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { ReleaseNotesWizard } from './wizard';

export const ReleaseNotesPage: FC = () => {
const [selectedVersion, setSelectedVersion] = useState<string>();
const [ignoredVersions, setIgnoredVersions] = useState<string[]>([]);
const [selectedServerlessSHAs, setSelectedServerlessSHAs] = useState<Set<string>>(new Set());

const onVersionChange = useCallback((version: string, ignoreVersions: string[] = []) => {
const onVersionChange = useCallback((version: string) => {
setSelectedVersion(version);
setIgnoredVersions(ignoreVersions);
}, []);

return (
Expand All @@ -24,7 +22,6 @@ export const ReleaseNotesPage: FC = () => {
{selectedVersion && (
<ReleaseNotes
version={selectedVersion}
ignoredPriorReleases={ignoredVersions}
selectedServerlessSHAs={selectedServerlessSHAs}
onVersionChange={() => setSelectedVersion(undefined)}
/>
Expand Down
26 changes: 19 additions & 7 deletions src/pages/release-notes/prepare-release-notes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { GroupedPrList, UncategorizedPr } from './components';

interface Props {
prs: PrItem[];
version: string;
}

export const PrepareReleaseNotes: FC<Props> = ({ prs }) => {
export const PrepareReleaseNotes: FC<Props> = ({ prs, version }) => {
const config = useActiveConfig();
const groupedPrs = useMemo(() => groupPrs(prs), [prs]);

Expand Down Expand Up @@ -49,7 +50,7 @@ export const PrepareReleaseNotes: FC<Props> = ({ prs }) => {
<ul>
{groupedPrs.missingLabel.map((pr) => (
<li key={pr.id}>
<Pr pr={pr} showAuthor={true} />
<Pr pr={pr} showAuthor={true} version={version} />
</li>
))}
</ul>
Expand All @@ -73,7 +74,7 @@ export const PrepareReleaseNotes: FC<Props> = ({ prs }) => {
<EuiSpacer size="m" />
{unknownPrs.map((pr) => (
<React.Fragment key={pr.id}>
<UncategorizedPr pr={pr} />
<UncategorizedPr pr={pr} version={version} />
<EuiSpacer size="s" />
</React.Fragment>
))}
Expand All @@ -87,7 +88,7 @@ export const PrepareReleaseNotes: FC<Props> = ({ prs }) => {
<ul>
{groupedPrs.breaking.map((pr) => (
<li key={`breaking-${pr.id}`}>
<Pr pr={pr} showTransformedTitle={true} />
<Pr pr={pr} showTransformedTitle={true} version={version} />
</li>
))}
</ul>
Expand All @@ -101,7 +102,7 @@ export const PrepareReleaseNotes: FC<Props> = ({ prs }) => {
<ul>
{groupedPrs.deprecation.map((pr) => (
<li key={`deprecation-${pr.id}`}>
<Pr pr={pr} showTransformedTitle={true} />
<Pr pr={pr} showTransformedTitle={true} version={version} />
</li>
))}
</ul>
Expand All @@ -112,7 +113,12 @@ export const PrepareReleaseNotes: FC<Props> = ({ prs }) => {
<h2>
Features (<EuiCode>release_note:feature</EuiCode>)
</h2>
<GroupedPrList groupedPrs={featurePrs} groups={config.areas} keyPrefix="features" />
<GroupedPrList
groupedPrs={featurePrs}
groups={config.areas}
keyPrefix="features"
version={version}
/>
</>
)}
{Object.keys(enhancementPrs).length > 0 && (
Expand All @@ -124,6 +130,7 @@ export const PrepareReleaseNotes: FC<Props> = ({ prs }) => {
groupedPrs={enhancementPrs}
groups={config.areas}
keyPrefix="enhancements"
version={version}
/>
</>
)}
Expand All @@ -132,7 +139,12 @@ export const PrepareReleaseNotes: FC<Props> = ({ prs }) => {
<h2>
Fixes (<EuiCode>release_note:fix</EuiCode>)
</h2>
<GroupedPrList groupedPrs={fixesPr} groups={config.areas} keyPrefix="fixes" />
<GroupedPrList
groupedPrs={fixesPr}
groups={config.areas}
keyPrefix="fixes"
version={version}
/>
</>
)}
</EuiText>
Expand Down
Loading