Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ temp/

dist/
build/

#Intellij
.idea
29 changes: 28 additions & 1 deletion src/js/actions/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ describe('actions/index.js', () => {
enterpriseAccounts: mockedEnterpriseAccounts,
},
notifications: { response: [] },
settings: {
usePAT: false,
},
},
expectedActions
);
Expand Down Expand Up @@ -433,10 +436,11 @@ describe('actions/index.js', () => {
token: 'THISISATOKEN',
enterpriseAccounts: mockedEnterpriseAccounts,
},
notifications: { response: [] },
settings: {
usePAT: false,
participating: false,
},
notifications: { response: [] },
},
expectedActions
);
Expand Down Expand Up @@ -470,6 +474,10 @@ describe('actions/index.js', () => {
token: 'THISISATOKEN',
enterpriseAccounts: mockedEnterpriseAccounts,
},
settings: {
usePAT: false,
participating: false,
},
notifications: { response: [] },
},
expectedActions
Expand Down Expand Up @@ -501,6 +509,7 @@ describe('actions/index.js', () => {
enterpriseAccounts: mockedEnterpriseAccounts,
},
settings: {
usePAT: false,
participating: false,
},
notifications: { response: [] },
Expand Down Expand Up @@ -536,6 +545,9 @@ describe('actions/index.js', () => {
enterpriseAccounts: mockedEnterpriseAccounts,
},
notifications: { response: [] },
settings: {
usePAT: false,
},
},
expectedActions
);
Expand Down Expand Up @@ -565,6 +577,9 @@ describe('actions/index.js', () => {
token: 'THISISATOKEN',
enterpriseAccounts: mockedEnterpriseAccounts,
},
settings: {
usePAT: false,
},
},
expectedActions
);
Expand Down Expand Up @@ -595,6 +610,9 @@ describe('actions/index.js', () => {
const store = createMockStore(
{
auth: { token: 'IAMATOKEN' },
settings: {
usePAT: false,
},
},
expectedActions
);
Expand Down Expand Up @@ -626,6 +644,9 @@ describe('actions/index.js', () => {
token: 'THISISATOKEN',
enterpriseAccounts: mockedEnterpriseAccounts,
},
settings: {
usePAT: false,
},
},
expectedActions
);
Expand Down Expand Up @@ -661,6 +682,9 @@ describe('actions/index.js', () => {
token: 'THISISATOKEN',
enterpriseAccounts: mockedEnterpriseAccounts,
},
settings: {
usePAT: false,
},
},
expectedActions
);
Expand Down Expand Up @@ -692,6 +716,9 @@ describe('actions/index.js', () => {
token: 'THISISATOKEN',
enterpriseAccounts: mockedEnterpriseAccounts,
},
settings: {
usePAT: false,
},
},
expectedActions
);
Expand Down
19 changes: 14 additions & 5 deletions src/js/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ export function fetchNotifications() {
}

const url = `https://api.${Constants.DEFAULT_AUTH_OPTIONS.hostname}/${endpointSuffix}`;
const token = getState().auth.token;
const token = settings.usePAT ? settings.patToken : getState().auth.token;
return apiRequestAuth(url, Methods.GET, token);
}

function getEnterpriseNotifications() {
const enterpriseAccounts = getState().auth.enterpriseAccounts;
return enterpriseAccounts.map((account) => {
const hostname = account.hostname;
const token = account.token;
const token = settings.usePAT ? settings.patToken : account.token;
const url = `https://${hostname}/api/v3/${endpointSuffix}`;
return apiRequestAuth(url, Methods.GET, token);
});
Expand Down Expand Up @@ -137,9 +137,12 @@ export function markNotification(id, hostname) {
return (dispatch, getState: () => AppState) => {
const url = `${generateGitHubAPIUrl(hostname)}notifications/threads/${id}`;

const { settings }: { settings: SettingsState } = getState();
const isEnterprise = hostname !== Constants.DEFAULT_AUTH_OPTIONS.hostname;
const entAccounts = getState().auth.enterpriseAccounts;
const token = isEnterprise
const token = settings.usePAT
? settings.patToken
: isEnterprise
? getEnterpriseAccountToken(hostname, entAccounts)
: getState().auth.token;

Expand Down Expand Up @@ -173,9 +176,12 @@ export function unsubscribeNotification(id, hostname) {
hostname
)}notifications/threads/${id}/subscription`;

const { settings }: { settings: SettingsState } = getState();
const isEnterprise = hostname !== Constants.DEFAULT_AUTH_OPTIONS.hostname;
const entAccounts = getState().auth.enterpriseAccounts;
const token = isEnterprise
const token = settings.usePAT
? settings.patToken
: isEnterprise
? getEnterpriseAccountToken(hostname, entAccounts)
: getState().auth.token;

Expand Down Expand Up @@ -214,9 +220,12 @@ export function markRepoNotifications(repoSlug, hostname) {
hostname
)}repos/${repoSlug}/notifications`;

const { settings }: { settings: SettingsState } = getState();
const isEnterprise = hostname !== Constants.DEFAULT_AUTH_OPTIONS.hostname;
const entAccounts = getState().auth.enterpriseAccounts;
const token = isEnterprise
const token = settings.usePAT
? settings.patToken
: isEnterprise
? getEnterpriseAccountToken(hostname, entAccounts)
: getState().auth.token;

Expand Down
6 changes: 6 additions & 0 deletions src/js/reducers/__snapshots__/settings.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ Object {
"markOnClick": false,
"openAtStartup": false,
"participating": true,
"patToken": "",
"playSound": true,
"showNotifications": true,
"usePAT": false,
}
`;

Expand All @@ -15,8 +17,10 @@ Object {
"markOnClick": false,
"openAtStartup": true,
"participating": false,
"patToken": "",
"playSound": true,
"showNotifications": true,
"usePAT": false,
}
`;

Expand All @@ -25,7 +29,9 @@ Object {
"markOnClick": false,
"openAtStartup": false,
"participating": false,
"patToken": "",
"playSound": true,
"showNotifications": true,
"usePAT": false,
}
`;
2 changes: 2 additions & 0 deletions src/js/reducers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const initialState: SettingsState = {
showNotifications: true,
markOnClick: false,
openAtStartup: false,
usePAT: false,
patToken: '',
};

export default function reducer(state = initialState, action): SettingsState {
Expand Down
75 changes: 75 additions & 0 deletions src/js/routes/__snapshots__/settings.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,81 @@ exports[`routes/settings.tsx should render itself & its children 1`] = `
</span>
</label>
</div>
<div
className="sc-AxjAm dnDkHN"
>
<label>
<div
className="sc-AxirZ gtlEvo"
>
<input
className="sc-AxhCb bORWEo"
label="Use PAT token instead of oauth"
name="usePAT"
onChange={[Function]}
type="checkbox"
/>
<div
className="sc-AxhUy juIZhB"
>
<svg
className="sc-AxiKw bCXYxk"
viewBox="0 0 24 24"
>
<g
fill="none"
fillRule="evenodd"
stroke="none"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1"
>
<g
stroke="#FFFFFF"
strokeWidth="3"
transform="translate(6.000000, 7.000000)"
>
<polyline
points="13 0 4.0625 9 0 4.90909091"
/>
</g>
</g>
</svg>
</div>
</div>
<span
style={
Object {
"marginLeft": "1rem",
}
}
>
Use PAT token instead of oauth
</span>
</label>
</div>
<div
style={
Object {
"display": "none",
}
}
>
<div>
<label
htmlFor="patTokenId"
>
Enter personal access token
</label>
</div>
<input
className="sc-fzplWN dtTksJ form-control"
id="patTokenId"
name="patToken"
onChange={[Function]}
type="password"
/>
</div>
<div
className="sc-AxjAm dnDkHN"
>
Expand Down
33 changes: 33 additions & 0 deletions src/js/routes/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ const ButtonFooter = styled.button`
}
`;

const InputField = styled.input`
width: 100%;
padding: 0.75em 1.25em;
margin: 0.5em 0;
display: inline-block;
border: 0.05em solid #ccc;
border-radius: 0.25em;
box-sizing: border-box;
`;

interface IProps {
hasMultipleAccounts: boolean;
fetchNotifications: () => any;
Expand Down Expand Up @@ -167,6 +177,29 @@ export class SettingsRoute extends React.Component<IProps> {
this.props.updateSetting('markOnClick', evt.target.checked)
}
/>
<FieldCheckbox
name="usePAT"
label="Use PAT token instead of oauth"
checked={settings.usePAT}
onChange={(evt) =>
this.props.updateSetting('usePAT', evt.target.checked)
}
/>
<div style={{ display: settings.usePAT ? 'block' : 'none' }}>
<div>
<label htmlFor="patTokenId">Enter personal access token</label>
</div>
<InputField
id="patTokenId"
name="patToken"
type="password"
value={settings.patToken}
onChange={(evt) =>
this.props.updateSetting('patToken', evt.target.value)
}
className="form-control"
/>
</div>
{!isLinux && (
<FieldCheckbox
name="openAtStartUp"
Expand Down
2 changes: 2 additions & 0 deletions src/types/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ export interface SettingsState {
showNotifications: boolean;
markOnClick: boolean;
openAtStartup: boolean;
usePAT: boolean;
patToken: string;
}