• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gitify-app / gitify / 9319904199

31 May 2024 02:38PM UTC coverage: 96.355% (-0.4%) from 96.787%
9319904199

Pull #1139

github

web-flow
Merge af6de505a into 72b432272
Pull Request #1139: feat(accounts): enhance auth account data structure

402 of 415 branches covered (96.87%)

Branch coverage included in aggregate %.

79 of 89 new or added lines in 12 files covered. (88.76%)

3 existing lines in 2 files now uncovered.

1052 of 1094 relevant lines covered (96.16%)

20.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.08
/src/utils/auth/migration.ts
1
import type { Account, AuthState } from '../../types';
2
import Constants from '../constants';
24✔
3
import { loadState, saveState } from '../storage';
24✔
4

5
/**
6
 * Migrate authenticated accounts from old data structure to new data structure (v5.7.0+).
7
 *
8
 * @deprecated We plan to remove this migration logic in a future major release.
9
 */
10
export function migrateAuthenticatedAccounts() {
24✔
11
  const existing = loadState();
22✔
12

13
  if (hasAccountsToMigrate(existing.auth)) {
22!
NEW
14
    console.log('Commencing authenticated accounts migration');
×
15

NEW
16
    const migratedAccounts = convertAccounts(existing.auth);
×
17

NEW
18
    saveState({
×
19
      auth: { ...existing.auth, accounts: migratedAccounts },
20
      settings: existing.settings,
21
    });
NEW
22
    console.log('Authenticated accounts migration complete');
×
23
  }
24
}
25

26
export function hasAccountsToMigrate(existingAuthState: AuthState): boolean {
24✔
27
  if (!existingAuthState) {
30✔
28
    return false;
24✔
29
  }
30

31
  if (existingAuthState?.accounts?.length > 0) {
6✔
32
    return false;
2✔
33
  }
34

35
  if (
4✔
36
    existingAuthState?.token ||
3✔
37
    existingAuthState?.enterpriseAccounts?.length > 0
38
  ) {
39
    return true;
4✔
40
  }
41

NEW
42
  return false;
×
43
}
44

45
export function convertAccounts(existingAuthState: AuthState): Account[] {
24✔
46
  const migratedAccounts: Account[] = [];
6✔
47

48
  if (existingAuthState?.token) {
6✔
49
    migratedAccounts.push({
4✔
50
      hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
51
      platform: 'GitHub Cloud',
52
      method: 'Personal Access Token',
53
      token: existingAuthState.token,
54
      user: existingAuthState.user,
55
    });
56
  }
57

58
  if (existingAuthState?.enterpriseAccounts) {
6✔
59
    for (const legacyEnterpriseAccount of existingAuthState.enterpriseAccounts) {
4✔
60
      migratedAccounts.push({
4✔
61
        hostname: legacyEnterpriseAccount.hostname,
62
        platform: 'GitHub Enterprise Server',
63
        method: 'OAuth App',
64
        token: legacyEnterpriseAccount.token,
65
        user: null,
66
      });
67
    }
68
  }
69

70
  return migratedAccounts;
6✔
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc