Skip to content

Commit

Permalink
add GitHub token validation
Browse files Browse the repository at this point in the history
  • Loading branch information
RayBB authored and johannesjo committed Jan 11, 2025
1 parent 36c20e7 commit 0585a8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/app/features/issue/providers/github/github.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../../config/global-config.model';
import { IssueProviderGithub } from '../../issue.model';
import { ISSUE_PROVIDER_COMMON_FORM_FIELDS } from '../../common-issue-form-stuff.const';
import { FormlyFieldConfig } from '@ngx-formly/core';

export const DEFAULT_GITHUB_CFG: GithubCfg = {
isEnabled: false,
Expand Down Expand Up @@ -42,8 +43,16 @@ export const GITHUB_CONFIG_FORM: LimitedFormlyFieldConfig<IssueProviderGithub>[]
props: {
label: T.F.GITHUB.FORM.TOKEN,
required: true,
placeholder: 'ghp_... (classic token)',
type: 'password',
},
validators: {
token: {
expression: (c: { value: string | undefined }) => c.value?.startsWith('ghp_'),
message: (error: any, field: FormlyFieldConfig) =>
`${field.formControl?.value} ${T.F.GITHUB.FORM.INVALID_TOKEN_MESSAGE}`,
},
},
},
{
type: 'link',
Expand Down
1 change: 1 addition & 0 deletions src/app/t.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ const T = {
IS_ASSIGNEE_FILTER: 'F.GITHUB.FORM.IS_ASSIGNEE_FILTER',
REPO: 'F.GITHUB.FORM.REPO',
TOKEN: 'F.GITHUB.FORM.TOKEN',
INVALID_TOKEN_MESSAGE: 'F.GITHUB.FORM.INVALID_TOKEN_MESSAGE',
},
FORM_SECTION: {
HELP: 'F.GITHUB.FORM_SECTION.HELP',
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@
"FILTER_USER": "Username (e.g. to filter out changes by yourself)",
"IS_ASSIGNEE_FILTER": "Only import issues assigned to me to backlog",
"REPO": "username/repositoryName",
"TOKEN": "Access Token"
"TOKEN": "Access Token",
"INVALID_TOKEN_MESSAGE": "is not a valid GitHub token. It must start with \"ghp_\"."
},
"FORM_SECTION": {
"HELP": "<p>Here you can configure SuperProductivity to list open GitHub issues for a specific repository in the task creation panel in the daily planning view. They will be listed as suggestions and will provide a link to the issue as well as more information about it.</p> <p>In addition you can automatically import all open issues.</p><p>To get by usage limits and to access you can provide a an access token. <a href='https://docs.github.com/en/free-pro-team@latest/developers/apps/scopes-for-oauth-apps'>More info about its scopes can be found here</a>.",
Expand Down

0 comments on commit 0585a8e

Please sign in to comment.