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

evolvedbinary / prosemirror-lwdita / 0377fb0b-2b09-4300-944c-6d1b0a47a7bb

18 Sep 2024 02:21PM UTC coverage: 59.688% (-1.0%) from 60.664%
0377fb0b-2b09-4300-944c-6d1b0a47a7bb

Pull #391

circleci

marmoure
[bugfix] exchangeOAuthCodeForAccessToken should only return the token not the object
Pull Request #391: Handle oauth response from github

188 of 385 branches covered (48.83%)

Branch coverage included in aggregate %.

23 of 47 new or added lines in 3 files covered. (48.94%)

1 existing line in 1 file now uncovered.

653 of 1024 relevant lines covered (63.77%)

20.07 hits per line

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

73.33
/packages/prosemirror-lwdita/src/github.plugin.ts
1
/*!
2
Copyright (C) 2020 Evolved Binary
3

4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU Affero General Public License as
6
published by the Free Software Foundation, either version 3 of the
7
License, or (at your option) any later version.
8

9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU Affero General Public License for more details.
13

14
You should have received a copy of the GNU Affero General Public License
15
along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
*/
17

18
import { xditaToJdita } from "@evolvedbinary/lwdita-xdita";
1✔
19
import { document as jditaToProsemirrorJson } from "./document";
1✔
20

21
/**
22
 * Fetches the raw content of a document from a GitHub repository.
23
 *
24
 * @param ghrepo - The GitHub repository in the format "owner/repo".
25
 * @param source - The path to the file within the repository.
26
 * @returns A promise that resolves to the raw content of the document as a string.
27
 *
28
 * @remarks
29
 * This function currently fetches the document from the 'main' branch of the repository.
30
 * should use the GitHub API to dynamically determine the default branch of the repository.
31
 */
32
export const fetchRawDocumentFromGitHub = async (ghrepo: string, source: string): Promise<string> => {
2✔
33
  //TODO(YB): the branch should be passed as a parameter
34
  const url = `https://raw.githubusercontent.com/${ghrepo}/main/${source}`;
2✔
35
  const response = await fetch(url);
2✔
36

37
  //TODO: Handle errors
38
  return response.text();
2✔
39
};
40

41
/**
42
 * Transforms a raw GitHub document into a ProseMirror state save.
43
 *
44
 * @param rawDocument - The raw xdita document as a string.
45
 * @returns A promise that resolves to a record containing the ProseMirror state save.
46
 */
47
// eslint-disable-next-line @typescript-eslint/no-explicit-any
48
export const transformGitHubDocumentToProsemirrorJson = async (rawDocument: string): Promise<Record<string, any>> => {
1✔
49
  // convert the raw xdita document to jdita
50
  const jdita = await xditaToJdita(rawDocument);
1✔
51

52
  // convert the jdita document to prosemirror state save
53
  const prosemirrorJson = await jditaToProsemirrorJson(jdita);
1✔
54

55
  return prosemirrorJson;
1✔
56
};
57

58
/**
59
 * Exchanges an OAuth code for an access token.
60
 *
61
 * @param code - The OAuth code to exchange for an access token.
62
 * @returns A promise that resolves to the access token as a string.
63
 * @throws Will throw an error if the fetch request fails or if the response is not in the expected format.
64
 */
65
export const exchangeOAuthCodeForAccessToken = async (code: string): Promise<string> => {
1✔
66
  // build the URL to exchange the code for an access token
NEW
67
  const url = `http://localhost:3000/api/github/token?code=${code}`;
×
68
  // fetch the access token
NEW
69
  const response = await fetch(url);
×
NEW
70
  const json = await response.json();
×
71
  //TODO: Handle errors
NEW
72
  return json;
×
73
};
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

© 2026 Coveralls, Inc