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
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ export default class GitGateway implements Implementation {
return {
name: userData.name,
login: userData.email,
email: userData.email,
avatar_url: userData.avatar_url,
} as unknown as User;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-backend-gitea/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class API {

static DEFAULT_COMMIT_MESSAGE = 'Automatically generated by Static CMS';

user(): Promise<{ full_name: string; login: string; avatar_url: string }> {
user(): Promise<{ full_name: string; login: string; email: string; avatar_url: string }> {
if (!this._userPromise) {
this._userPromise = this.getUser();
}
Expand Down
1 change: 1 addition & 0 deletions packages/decap-cms-backend-gitea/src/implementation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export default class Gitea implements Implementation {
return {
name: user.full_name,
login: user.login,
email: user.email,
avatar_url: user.avatar_url,
token: state.token as string,
};
Expand Down
3 changes: 2 additions & 1 deletion packages/decap-cms-backend-github/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,14 @@ export default class API {

static DEFAULT_COMMIT_MESSAGE = 'Automatically generated by Decap CMS';

user(): Promise<{ name: string; login: string }> {
user(): Promise<{ name: string; login: string; email?: string }> {
if (!this._userPromise) {
this._userPromise = this.getUser({ token: this.token });
}
return this._userPromise.then(user => ({
name: user.name || 'Unknown',
login: user.login,
email: user.email ?? undefined,
}));
}

Expand Down
1 change: 1 addition & 0 deletions packages/decap-cms-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ declare module 'decap-cms-core' {
auth_type?: 'implicit' | 'pkce';
cms_label_prefix?: string;
squash_merges?: boolean;
signoff_commits?: boolean;
proxy_url?: string;
commit_messages?: {
create?: string;
Expand Down
4 changes: 4 additions & 0 deletions packages/decap-cms-core/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ export class Backend {
path,
authorLogin: user.login,
authorName: user.name,
authorEmail: user.email,
},
user.useOpenAuthoring,
);
Expand Down Expand Up @@ -1253,6 +1254,7 @@ export class Backend {
path: file.path,
authorLogin: user.login,
authorName: user.name,
authorEmail: user.email,
},
user.useOpenAuthoring,
),
Expand All @@ -1279,6 +1281,7 @@ export class Backend {
path,
authorLogin: user.login,
authorName: user.name,
authorEmail: user.email,
},
user.useOpenAuthoring,
);
Expand All @@ -1303,6 +1306,7 @@ export class Backend {
path,
authorLogin: user.login,
authorName: user.name,
authorEmail: user.email,
},
user.useOpenAuthoring,
);
Expand Down
21 changes: 21 additions & 0 deletions packages/decap-cms-core/src/lib/__tests__/formatters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,27 @@ describe('formatters', () => {
'Ignoring unknown variable “author-email” in open authoring message template.',
);
});

it('should return commit with trailer when signoff_commits is enabled', () => {
const collection = Map({ label_singular: 'Collection' });
const config = {
backend: {
signoff_commits: true,
},
};

expect(
commitMessageFormatter('create', config, {
slug: 'doc-slug',
path: 'file-path',
collection,
authorName: 'Test User',
authorEmail: 'test-user@example.org',
}),
).toEqual(
'Create Collection “doc-slug”\n\nSigned-off-by: Test User <test-user@example.org>\n',
);
});
});

describe('prepareSlug', () => {
Expand Down
18 changes: 15 additions & 3 deletions packages/decap-cms-core/src/lib/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,28 @@ type Options = {
collection?: Collection;
authorLogin?: string;
authorName?: string;
authorEmail?: string;
};

export function commitMessageFormatter(
type: keyof typeof commitMessageTemplates,
config: CmsConfig,
{ slug, path, collection, authorLogin, authorName }: Options,
{ slug, path, collection, authorLogin, authorName, authorEmail }: Options,
isOpenAuthoring?: boolean,
) {
const templates = { ...commitMessageTemplates, ...(config.backend.commit_messages || {}) };

let trailers = '';
if (config.backend.signoff_commits) {
if (!authorName) {
console.warn('Option signoff_commits is enabled, but author name is unknown');
} else if (!authorEmail) {
console.warn('Option signoff_commits is enabled, but author email is unknown');
} else {
trailers = `\n\nSigned-off-by: ${authorName} <${authorEmail}>\n`;
}
}

const commitMessage = templates[type].replace(variableRegex, (_, variable) => {
switch (variable) {
case 'slug':
Expand All @@ -73,7 +85,7 @@ export function commitMessageFormatter(
});

if (!isOpenAuthoring) {
return commitMessage;
return commitMessage + trailers;
}

const message = templates.openAuthoring.replace(variableRegex, (_, variable) => {
Expand All @@ -90,7 +102,7 @@ export function commitMessageFormatter(
}
});

return message;
return message + trailers;
}

export function prepareSlug(slug: string) {
Expand Down
1 change: 1 addition & 0 deletions packages/decap-cms-core/src/types/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ export interface CmsBackend {
auth_endpoint?: string;
cms_label_prefix?: string;
squash_merges?: boolean;
signoff_commits?: boolean;
proxy_url?: string;
commit_messages?: {
create?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/decap-cms-lib-util/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export type Credentials = { token: string | {}; refresh_token?: string };
export type User = Credentials & {
backendName?: string;
login?: string;
email?: string;
name: string;
useOpenAuthoring?: boolean;
};
Expand Down
Loading