feat: display author of changes in workflow tab (#5780)

This commit is contained in:
pr0grammm
2021-10-18 17:08:38 +05:30
committed by GitHub
parent 9627452de0
commit 3f607e41d9
30 changed files with 288 additions and 233 deletions

View File

@ -62,6 +62,10 @@ type AzurePullRequest = {
pullRequestId: number;
labels: AzureWebApiTagDefinition[];
sourceRefName: string;
createdBy?: {
displayName?: string;
uniqueName: string;
};
};
type AzurePullRequestCommit = { commitId: string };
@ -458,12 +462,15 @@ export default class API {
const status = labelToStatus(labelName, this.cmsLabelPrefix);
// Uses creationDate, as we do not have direct access to the updated date
const updatedAt = pullRequest.closedDate ? pullRequest.closedDate : pullRequest.creationDate;
const pullRequestAuthor =
pullRequest.createdBy?.displayName || pullRequest.createdBy?.uniqueName;
return {
collection,
slug,
status,
diffs: diffsWithIds,
updatedAt,
pullRequestAuthor,
};
}

View File

@ -84,6 +84,7 @@ type BitBucketPullRequest = {
name: string;
};
};
author: BitBucketUser;
};
type BitBucketPullRequests = {
@ -699,6 +700,7 @@ export default class API {
const label = await this.getPullRequestLabel(pullRequest.id);
const status = labelToStatus(label, this.cmsLabelPrefix);
const updatedAt = pullRequest.updated_on;
const pullRequestAuthor = pullRequest.author.display_name;
return {
collection,
slug,
@ -708,6 +710,7 @@ export default class API {
.filter(d => d.status !== 'deleted')
.map(d => ({ path: d.path, newFile: d.newFile, id: '' })),
updatedAt,
pullRequestAuthor,
};
}

View File

@ -570,11 +570,27 @@ export default class API {
}
}
async getPullRequestAuthor(pullRequest: Octokit.PullsListResponseItem) {
if (!pullRequest.user?.login) {
return;
}
try {
const user: GitHubUser = await this.request(`/users/${pullRequest.user.login}`);
return user.name || user.login;
} catch {
return;
}
}
async retrieveUnpublishedEntryData(contentKey: string) {
const { collection, slug } = this.parseContentKey(contentKey);
const branch = branchFromContentKey(contentKey);
const pullRequest = await this.getBranchPullRequest(branch);
const { files } = await this.getDifferences(this.branch, pullRequest.head.sha);
const [{ files }, pullRequestAuthor] = await Promise.all([
this.getDifferences(this.branch, pullRequest.head.sha),
this.getPullRequestAuthor(pullRequest),
]);
const diffs = await Promise.all(files.map(file => this.diffFromFile(file)));
const label = pullRequest.labels.find(l => isCMSLabel(l.name, this.cmsLabelPrefix)) as {
name: string;
@ -587,6 +603,7 @@ export default class API {
status,
diffs: diffs.map(d => ({ path: d.path, newFile: d.newFile, id: d.sha })),
updatedAt,
pullRequestAuthor,
};
}

View File

@ -72,6 +72,14 @@ type GraphQLPullRequest = {
id: string;
isFork: boolean;
};
user: GraphQLPullsListResponseItemUser;
};
type GraphQLPullsListResponseItemUser = {
avatar_url: string;
login: string;
url: string;
name: string;
};
function transformPullRequest(pr: GraphQLPullRequest) {
@ -272,6 +280,11 @@ export default class GraphQLAPI extends API {
}
}
async getPullRequestAuthor(pullRequest: Octokit.PullsListResponseItem) {
const user = pullRequest.user as unknown as GraphQLPullsListResponseItemUser;
return user?.name || user?.login;
}
async getPullRequests(
head: string | undefined,
state: PullRequestState,

View File

@ -51,6 +51,12 @@ export const pullRequest = gql`
title
merged_at: mergedAt
updated_at: updatedAt
user: author {
login
... on User {
name
}
}
repository {
...RepositoryParts
}

View File

@ -655,12 +655,14 @@ export default class API {
const label = mergeRequest.labels.find(l => isCMSLabel(l, this.cmsLabelPrefix)) as string;
const status = labelToStatus(label, this.cmsLabelPrefix);
const updatedAt = mergeRequest.updated_at;
const pullRequestAuthor = mergeRequest.author.name;
return {
collection,
slug,
status,
diffs: diffsWithIds,
updatedAt,
pullRequestAuthor,
};
}

View File

@ -882,6 +882,7 @@ export class Backend {
label: collection && selectFileEntryLabel(collection, slug),
mediaFiles,
updatedOn: entryData.updatedAt,
author: entryData.pullRequestAuthor,
status: entryData.status,
meta: { path: prepareMetaPath(path, collection) },
});

View File

@ -128,12 +128,14 @@ function WorkflowCard({
allowPublish,
canPublish,
onPublish,
postAuthor,
t,
}) {
return (
<WorkflowCardContainer>
<WorkflowLink to={editLink}>
<CardCollection>{collectionLabel}</CardCollection>
{postAuthor}
<CardTitle>{title}</CardTitle>
{(timestamp || authorLastChange) && <CardDate date={timestamp} author={authorLastChange} />}
<CardBody>{body}</CardBody>
@ -168,6 +170,7 @@ WorkflowCard.propTypes = {
allowPublish: PropTypes.bool.isRequired,
canPublish: PropTypes.bool.isRequired,
onPublish: PropTypes.func.isRequired,
postAuthor: PropTypes.string,
t: PropTypes.func.isRequired,
};

View File

@ -220,6 +220,7 @@ class WorkflowList extends React.Component {
const allowPublish = collection?.get('publish');
const canPublish = ownStatus === status.last() && !entry.get('isPersisting', false);
const postAuthor = entry.get('author');
return (
<DragSource
@ -244,6 +245,7 @@ class WorkflowList extends React.Component {
allowPublish={allowPublish}
canPublish={canPublish}
onPublish={this.requestPublish.bind(this, collectionName, slug, ownStatus)}
postAuthor={postAuthor}
/>
</div>,
)

View File

@ -40,6 +40,7 @@ export interface UnpublishedEntryDiff {
}
export interface UnpublishedEntry {
pullRequestAuthor?: string;
slug: string;
collection: string;
status: string;