Skip to content

Commit 1af3c16

Browse files
committed
fix: revert the changes done to base_url
1 parent 0a2e3de commit 1af3c16

File tree

5 files changed

+90
-15
lines changed

5 files changed

+90
-15
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Start Patch
2626
uses: pkgjs/patch-my-code-of-conduct@v1.0.3
2727
with:
28-
base_url: 'https://raw.githubusercontent.com/openjs-foundation/cross-project-council/240d047d4f2cb135e6c1ce64b036af7aaf639a01/meetings/2023/2023-01-03.md'
28+
base_url: './BASE.md'
2929
patch_file_path: './patch'
3030
output_file_path: './CODE_OF_CONDUCT.md'
3131
- uses: gr2m/create-or-update-pull-request-action@v1

lib/runner.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ const { execSync } = require('node:child_process')
33
const { fetch } = require('undici')
44

55
async function apply_patch(base_url, template_url, patch_path, output_path) {
6-
const base_response = await fetch(base_url);
7-
8-
if (base_response.status !== 200 && base_response.status !== 201) {
9-
throw new Error(`base url response got ${base_url.status} status code. expected 200 or 201.`)
6+
if (!fs.existsSync(base_url)) {
7+
throw new Error(`base_url (${base_url}) does not exist`)
108
}
11-
const base_text = await base_response.text();
12-
9+
const base_text = fs.readFileSync(base_url, 'utf-8');
1310
const template_response = await fetch(template_url);
1411

1512
if (template_response.status !== 200 && template_response.status !== 201) {

test/apply.test.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,53 @@ import {random_filename, write_file, remove_file, read_file, __dirname} from "./
44
import {apply_patch} from '../lib/runner.js'
55

66
beforeEach(async (context) => {
7-
context.base_url = 'https://raw.githubusercontent.com/pkgjs/patch-my-code-of-conduct/cd136b70909ad4c14d738d0399e09559ca2a3ecd/template/base.md'
7+
context.base_url = random_filename()
88
context.template_url = 'https://www.contributor-covenant.org/version/2/1/code_of_conduct/code_of_conduct.md';
99
context.patch_path = random_filename()
1010
context.output_path = random_filename()
1111

12+
await write_file(context.base_url)
1213
await write_file(context.patch_path)
1314
await write_file(context.output_path)
1415

1516
return async () => {
17+
await remove_file(context.base_url)
1618
await remove_file(context.patch_path)
1719
await remove_file(context.output_path)
1820
}
1921
})
2022

2123
test('should add base as prefix', async (context) => {
24+
await write_file(context.base_url, 'this is a prefix')
2225
await apply_patch(context.base_url, context.template_url, context.patch_path, context.output_path)
2326
const output = await read_file(context.output_path)
24-
assert.isTrue(output.startsWith('This is the beginning of our Code of Conduct.\n'))
27+
assert.isTrue(output.startsWith('this is a prefix\n'))
2528
})
29+
30+
test('should apply the patch', async (context) => {
31+
const base_url = path.join(__dirname, '../test/fixture/base.md');
32+
const patch_path = path.join(__dirname, '../test/fixture/patch.txt');
33+
const output_path = path.join(__dirname, '../test/fixture/output.md');
34+
35+
await remove_file(output_path);
36+
37+
const title = `CHANGED THE TITLE OF COC`
38+
const patch_text = `--- test/fixture/output.md 2023-02-07 13:42:23
39+
+++ ./test/output-new.md 2023-02-07 13:43:41
40+
@@ -43,7 +43,7 @@
41+
42+
---
43+
44+
-# CHANGED THE TITLE OF COC
45+
+# Contributor Covenant Code of Conduct
46+
47+
## Our Pledge
48+
49+
50+
`
51+
await write_file(patch_path, patch_text)
52+
53+
await apply_patch(base_url, context.template_url, patch_path, output_path)
54+
const output = await read_file(output_path)
55+
assert.isTrue(output.includes(title))
56+
})

test/fixture/base.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Code of Conduct
2+
3+
The OpenJS Foundation and its member projects use [Contributor Covenant v2.0](https://contributor-covenant.org/version/2/0/code_of_conduct) as their code of conduct. The full text is included [below](#contributor-covenant-code-of-conduct-v20) in English, and [translations](https://www.contributor-covenant.org/translations) are available on the Contributor Covenant website.
4+
5+
## Commitment
6+
7+
All recipients of reports commit to:
8+
9+
- maintain the confidentiality with regard to the reporter and victim of an incident, and
10+
- participate in the path for escalation as outlined in the section on Escalation when required.
11+
12+
## Report an issue in a project
13+
14+
1. To report an issue in one of the projects listed below, please use the method provided. The project itself is responsible for managing these reports.
15+
* **AMP Project:** <code-of-conduct@amp.dev>
16+
* **Appium:** email maintainers
17+
* **Electron:** <coc@electronjs.org>
18+
* **Express.js:** <express-coc@lists.openjsf.org>
19+
* **Fastify:** <hello@matteocollina.com> or <tommydelved@gmail.com>
20+
* **HospitalRun:** <hello@hospitalrun.io>
21+
* **LoopBack** <tsc@loopback.io>
22+
* **Node.js:** <report@nodejs.org>
23+
* **Node-RED:** <team@nodered.org>
24+
* **Webdriver.io:** [contact TSC reps](https://github.com/webdriverio/webdriverio/blob/HEAD/AUTHORS.md)
25+
* **Webhint:** <support@webhint.io>
26+
2. For every other OpenJS Foundation project, please email <report@lists.openjsf.org>. The Cross Project Council (CPC) is responsible for managing these reports.
27+
28+
29+
## Report an issue in a space managed by the foundation
30+
31+
For reporting issues in spaces managed by the OpenJS Foundation, for example, repositories within the OpenJS organization or an live event such as a conferences, email <report@lists.openjsf.org>. The Cross Project Council (CPC) is responsible for managing these reports.
32+
33+
## Escalate an issue
34+
35+
The OpenJS Foundation maintains a [Code of Conduct Panel (CoCP)](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/conduct/FOUNDATION_CODE_OF_CONDUCT_REQUIREMENTS.md#code-of-conduct-panel). This is a foundation-wide team established to manage escalation when a reporter believes that a report to a member project or the CPC has not been properly handled.
36+
37+
In order to escalate to the CoCP, email <coc-escalation@lists.openjsf.org>.
38+
39+
## More Info
40+
41+
For more information, refer to the full
42+
[Code of Conduct governance document](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/conduct/FOUNDATION_CODE_OF_CONDUCT_REQUIREMENTS.md).
43+
44+
---
45+

test/fixture/patch.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
--- /dev/null 2022-11-11 18:00:48
2-
+++ output.md 2022-11-11 18:00:32
3-
@@ -1,6 +1,6 @@
4-
This is the beginning of our Code of Conduct.
1+
--- test/fixture/output.md 2023-02-07 13:42:23
2+
+++ ./test/output-new.md 2023-02-07 13:43:41
3+
@@ -43,7 +43,7 @@
54

6-
-# Contributor Covenant Code of Conduct
7-
+# CHANGED_THE_TITLE
5+
---
6+
7+
-# CHANGED THE TITLE OF COC
8+
+# Contributor Covenant Code of Conduct
89

910
## Our Pledge
1011

12+

0 commit comments

Comments
 (0)