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

gitify-app / gitify / 9320225782

31 May 2024 03:03PM UTC coverage: 96.429% (-0.4%) from 96.787%
9320225782

Pull #1139

github

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

402 of 415 branches covered (96.87%)

Branch coverage included in aggregate %.

83 of 93 new or added lines in 12 files covered. (89.25%)

2 existing lines in 1 file now uncovered.

1056 of 1097 relevant lines covered (96.26%)

20.47 hits per line

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

82.5
/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
import { getUserData } from './utils';
24✔
5

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

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

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

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

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

32
  // Don't attempt migration if there are already accounts in the new structure
33
  if (existingAuthState?.accounts?.length > 0) {
6✔
34
    return false;
2✔
35
  }
36

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

NEW
44
  return false;
×
45
}
46

47
export async function convertAccounts(
24✔
48
  existingAuthState: AuthState,
49
): Promise<Account[]> {
50
  const migratedAccounts: Account[] = [];
6✔
51

52
  if (existingAuthState?.token) {
6✔
53
    const user = await getUserData(
4✔
54
      existingAuthState.token,
55
      Constants.DEFAULT_AUTH_OPTIONS.hostname,
56
    );
57

58
    migratedAccounts.push({
4✔
59
      hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
60
      platform: 'GitHub Cloud',
61
      method: 'Personal Access Token',
62
      token: existingAuthState.token,
63
      user: user,
64
    });
65
  }
66

67
  if (existingAuthState?.enterpriseAccounts) {
6✔
68
    for (const legacyEnterpriseAccount of existingAuthState.enterpriseAccounts) {
4✔
69
      const user = await getUserData(
4✔
70
        legacyEnterpriseAccount.token,
71
        legacyEnterpriseAccount.hostname,
72
      );
73

74
      migratedAccounts.push({
4✔
75
        hostname: legacyEnterpriseAccount.hostname,
76
        platform: 'GitHub Enterprise Server',
77
        method: 'OAuth App',
78
        token: legacyEnterpriseAccount.token,
79
        user: user,
80
      });
81
    }
82
  }
83

84
  return migratedAccounts;
6✔
85
}
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