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

evolvedbinary / prosemirror-lwdita / 5544ce50-4e90-4a79-a163-2c2f68971a0a

12 Sep 2024 09:04AM UTC coverage: 60.443% (-0.5%) from 60.954%
5544ce50-4e90-4a79-a163-2c2f68971a0a

push

circleci

marmoure
[feature] create a pr from user contribution

188 of 370 branches covered (50.81%)

Branch coverage included in aggregate %.

1 of 13 new or added lines in 1 file covered. (7.69%)

631 of 985 relevant lines covered (64.06%)

20.79 hits per line

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

47.83
/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
  // https://raw.githubusercontent.com/evolvedbinary/prosemirror-lwdita/main/packages/prosemirror-lwdita-demo/example-xdita/02-short-file.xml
34
  // We have an issue of the branch, we should use the default branch of the repo
35
  //TODO(YB): We should use the GitHub API to get the default branch of the repo
36
  const url = `https://raw.githubusercontent.com/${ghrepo}/main/${source}`;
2✔
37
  const response = await fetch(url);
2✔
38

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

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

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

57
  return prosemirrorJson;
1✔
58
};
59

60
/**
61
 * Publishes a document to a specified GitHub repository.
62
 * Makes a POST request to the `/api/github/integration` endpoint with the necessary details to create a pull request.
63
 * 
64
 * @param ghrepo - The GitHub repository in the format "owner/repo".
65
 * @param source - The path to the source document.
66
 * @param changedDocument - The content of the changed document.
67
 * @returns A promise that resolves when the document has been published.
68
 */
69
export const createPrFromContribution = async (ghrepo: string, source: string, changedDocument: string): Promise<void> => {
1✔
NEW
70
  const owner = ghrepo.split('/')[0];
×
NEW
71
  const repo = ghrepo.split('/')[1];
×
NEW
72
  const newOwner = "marmoure";
×
NEW
73
  const newBranch = "new-branch";
×
NEW
74
  const commitMessage = "Update the document";
×
NEW
75
  const path = source;
×
NEW
76
  const content = changedDocument;
×
NEW
77
  const change = {
×
78
    path,
79
    content
80
  };
NEW
81
  const title = "Update the document";
×
NEW
82
  const body = "Update the document ------------------ This is an automated PR made by the prosemirror-lwdita demo"; 
×
83

84
  // get the token from the local storage
NEW
85
  const token = localStorage.getItem('token');
×
86

87
  // make a post request to  /api/github/integration
NEW
88
  fetch('/api/github/integration', {
×
89
    method: 'POST',
90
    headers: {
91
      'Content-Type': 'application/json',
92
      'Authorization': `Bearer ${token}`
93
    },
94
    body: JSON.stringify({
95
      owner,
96
      repo,
97
      newOwner,
98
      newBranch,
99
      commitMessage,
100
      change,
101
      title,
102
      body
103
    })
104
  });
105

106
};
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