Skip to content

Commit

Permalink
Fix integration test (#13)
Browse files Browse the repository at this point in the history
* add minimal example json from opened pr with dependabot body

* add event json to test_util module

* use fake event json in run-fake and in integration test

* update version example in Readme

* ignore test_data dir when checking for typos
  • Loading branch information
CramBL authored Dec 28, 2024
1 parent 0082a66 commit 0ec44a1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./
with:
push_changes: false
env:
USE_FAKE_EVENT_JSON: test_data/event_json/minimal_pr_opened.json

test_error:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ run \
$GITHUB_OUTPUT \
$GH_TOKEN \
$PUSH_TOKEN \
$GITHUB_EVENT_PATH \
$USE_FAKE_EVENT_JSON \
CHANGELOG \
COMMIT_MSG \
COMMITTER_NAME \
Expand All @@ -19,7 +19,7 @@ run-fake: (run \
"test_github_output_path" \
"test_github_token" \
"test_push_token" \
"Cargo.toml" \
"test_data/event_json/minimal_pr_opened.json" \
"CHANGELOG.md" \
"fake commit message" \
"fake commit name" \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
If you have checks that are gets invalidated by in-workflow pushes you can add a PAT to make CI trigger on the push
```yaml
- uses: crambl/dependabot-changelog-writer@v0.1.2
- uses: crambl/dependabot-changelog-writer@v1.0.0
with:
push_token: ${{ secrets.PAT_PUSH }} # Just needs 'public_repo' scope if your repo is public otherwise needs 'repo'
```
Expand Down
20 changes: 13 additions & 7 deletions src/event_json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{env, path::PathBuf};

use crate::github_env::github_event_path;

Expand All @@ -12,20 +12,26 @@ pub struct GithubEvent {
impl GithubEvent {
/// Read and parse the event file
pub fn load_from_env() -> Result<Self> {
// Read the event path environment variable
let event_path = github_event_path();
log::debug!("event_path={event_path}");
let event_path = PathBuf::from(event_path);
// Read the event path environment variable, use the fake one event JSON if it is set
let event_path = match env::var("USE_FAKE_EVENT_JSON") {
Ok(fake_event_json) => PathBuf::from(fake_event_json),
Err(_) => PathBuf::from(github_event_path()),
};
log::debug!("event_path={}", event_path.display());

if !event_path.is_file() {
return Err(format!("No github event file at: {}", event_path.display()).into());
}

GithubEvent::new(event_path)
Self::from_path(event_path)
}

pub fn new(event_json_path: PathBuf) -> Result<Self> {
pub fn from_path(event_json_path: PathBuf) -> Result<Self> {
let event_json = std::fs::read_to_string(event_json_path)?;
Self::new(event_json)
}

pub fn new(event_json: String) -> Result<Self> {
log::debug!("event_json={event_json}");
let event: serde_json::Value =
serde_json::from_str(&event_json).map_err(|e| format!("Malformed event JSON: {e}"))?;
Expand Down
6 changes: 5 additions & 1 deletion src/test_util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
pub mod example_changelogs;
pub mod example_dependabot_pr_bodies;
pub mod example_event_json;
pub mod example_parsed_changes;

#[allow(unused_imports)]
pub use {example_changelogs::*, example_dependabot_pr_bodies::*, example_parsed_changes::*};
pub use {
example_changelogs::*, example_dependabot_pr_bodies::*, example_event_json::*,
example_parsed_changes::*,
};
6 changes: 6 additions & 0 deletions src/test_util/example_event_json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// Minimal event JSON from an opened PR with the body from a dependabot update
/// contains only the fields we use:
/// - ["pull_request"]["head"]["ref"]
/// - ["pull_request"]["body"]
pub const EXAMPLE_PR_OPENED_EVENT_JSON: &str =
include_str!("../../test_data/event_json/minimal_pr_opened.json");
8 changes: 8 additions & 0 deletions test_data/event_json/minimal_pr_opened.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"pull_request": {
"body": "Bumps the github_actions group with 2 updates in the / directory: [crate-ci/typos](https://github.com/crate-ci/typos) and [docker/login-action](https://github.com/docker/login-action).\r\n\r\nUpdates `crate-ci/typos` from 1.27.0 to 1.28.4\r\n<details>\r\n<summary>Release notes</summary>\r\n<p><em>Sourced from <a href=\"https://github.com/crate-ci/typos/releases\">crate-ci/typos's releases</a>.</em></p>\r\n<blockquote>\r\n<h2>v1.28.4</h2>\r\n<h2>[1.28.4] - 2024-12-16</h2>\r\n<h3>Features</h3>\r\n<ul>\r\n<li><code>--format sarif</code> support</li>\r\n</ul>\r\n<h2>v1.28.3</h2>\r\n<h2>[1.28.3] - 2024-12-12</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Correct <code>imlementations</code>, <code>includs</code>, <code>qurorum</code>, <code>transatctions</code>, <code>trasnactions</code>, <code>validasted</code>, <code>vview</code></li>\r\n</ul>\r\n<h2>v1.28.2</h2>\r\n<h2>[1.28.2] - 2024-12-02</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Don't correct <code>parametrize</code> variants</li>\r\n</ul>\r\n<h2>v1.28.1</h2>\r\n<h2>[1.28.1] - 2024-11-26</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Add back in <code>lock</code> file types accidentally removed in 1.28 (<code>go.sum</code>, <code>requirements.txt</code>)</li>\r\n</ul>\r\n<h2>v1.28.0</h2>\r\n<h2>[1.28.0] - 2024-11-25</h2>\r\n<h3>Features</h3>\r\n<ul>\r\n<li>Updated the dictionary with the <a href=\"https://redirect.github.com/crate-ci/typos/issues/1139\">November 2024</a> changes</li>\r\n<li>Add many new types and file extensions to the <code>--type-list</code>, including ada, alire, bat, candid, carp, cml, devicetree, dita, dockercompose, grpbuild, graphql, hare, lean, meson, prolog, raku, reasonml, rescript, solidity, svelte, usd, v, wgsl</li>\r\n</ul>\r\n<h2>v1.27.3</h2>\r\n<h2>[1.27.3] - 2024-11-08</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Don't correct <code>alloced</code></li>\r\n<li>Don't correct <code>registor</code>, a more domain specific variant of <code>register</code></li>\r\n</ul>\r\n<h2>v1.27.2</h2>\r\n<h2>[1.27.2] - 2024-11-06</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Correct <code>fand</code></li>\r\n</ul>\r\n<!-- raw HTML omitted -->\r\n</blockquote>\r\n<p>... (truncated)</p>\r\n</details>\r\n<details>\r\n<summary>Changelog</summary>\r\n<p><em>Sourced from <a href=\"https://github.com/crate-ci/typos/blob/master/CHANGELOG.md\">crate-ci/typos's changelog</a>.</em></p>\r\n<blockquote>\r\n<h1>Change Log</h1>\r\n<p>All notable changes to this project will be documented in this file.</p>\r\n<p>The format is based on <a href=\"http://keepachangelog.com/\">Keep a Changelog</a>\r\nand this project adheres to <a href=\"http://semver.org/\">Semantic Versioning</a>.</p>\r\n<!-- raw HTML omitted -->\r\n<h2>[Unreleased] - ReleaseDate</h2>\r\n<h2>[1.28.4] - 2024-12-16</h2>\r\n<h3>Features</h3>\r\n<ul>\r\n<li><code>--format sarif</code> support</li>\r\n</ul>\r\n<h2>[1.28.3] - 2024-12-12</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Correct <code>imlementations</code>, <code>includs</code>, <code>qurorum</code>, <code>transatctions</code>, <code>trasnactions</code>, <code>validasted</code>, <code>vview</code></li>\r\n</ul>\r\n<h2>[1.28.2] - 2024-12-02</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Don't correct <code>parametrize</code> variants</li>\r\n</ul>\r\n<h2>[1.28.1] - 2024-11-26</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Add back in <code>lock</code> file types accidentally removed in 1.28 (<code>go.sum</code>, <code>requirements.txt</code>)</li>\r\n</ul>\r\n<h2>[1.28.0] - 2024-11-25</h2>\r\n<h3>Features</h3>\r\n<ul>\r\n<li>Updated the dictionary with the <a href=\"https://redirect.github.com/crate-ci/typos/issues/1139\">November 2024</a> changes</li>\r\n<li>Add many new types and file extensions to the <code>--type-list</code>, including ada, alire, bat, candid, carp, cml, devicetree, dita, dockercompose, grpbuild, graphql, hare, lean, meson, prolog, raku, reasonml, rescript, solidity, svelte, usd, v, wgsl</li>\r\n</ul>\r\n<h2>[1.27.3] - 2024-11-08</h2>\r\n<h3>Fixes</h3>\r\n<ul>\r\n<li>Don't correct <code>alloced</code></li>\r\n<li>Don't correct <code>requestor</code>, a more domain specific variant of <code>requester</code></li>\r\n</ul>\r\n<h2>[1.27.2] - 2024-11-06</h2>\r\n<h3>Fixes</h3>\r\n<!-- raw HTML omitted -->\r\n</blockquote>\r\n<p>... (truncated)</p>\r\n</details>\r\n<details>\r\n<summary>Commits</summary>\r\n<ul>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/9d890159570d5018df91fedfa40b4730cd4a81b1\"><code>9d89015</code></a> chore: Release</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/6b24563a993736342606b02dc6f98c7d86197fac\"><code>6b24563</code></a> chore: Release</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/bd0a2769ae8d608b6e8152aff91e91d7d2aad0f3\"><code>bd0a276</code></a> docs: Update changelog</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/370109dd4d88cfe9d647eb6cc9ed23e64cc75f8a\"><code>370109d</code></a> Merge pull request <a href=\"https://redirect.github.com/crate-ci/typos/issues/1047\">#1047</a> from Zxilly/sarif</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/63908449a70239a7719ed21f1caaca964c001470\"><code>6390844</code></a> feat: Implement sarif format reporter</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/32b96444b9239039a8977dc5fc82e46732b77844\"><code>32b9644</code></a> Merge pull request <a href=\"https://redirect.github.com/crate-ci/typos/issues/1169\">#1169</a> from klensy/deps</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/720258f60bee6e05a3307b2ef7e7574d9d19f2d9\"><code>720258f</code></a> Merge pull request <a href=\"https://redirect.github.com/crate-ci/typos/issues/1176\">#1176</a> from Ghaniyyat05/master</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/a42904ad6e5d5533d2dc478538bf379b0189d20a\"><code>a42904a</code></a> Update README.md</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/d1c850b2b5d502763520c25fb4a6a1128ad99bd9\"><code>d1c850b</code></a> chore: Release</li>\r\n<li><a href=\"https://github.com/crate-ci/typos/commit/a491fd56c00b86bed2e822c3fbe3bb4b8f5baca3\"><code>a491fd5</code></a> chore: Release</li>\r\n<li>Additional commits viewable in <a href=\"https://github.com/crate-ci/typos/compare/d01f29c66d1bf1a08730750f61d86c210b0d039d...9d890159570d5018df91fedfa40b4730cd4a81b1\">compare view</a></li>\r\n</ul>\r\n</details>\r\n<br />\r\n\r\nUpdates `docker/login-action` from 3d58c274f17dffee475a5520cbe67f0a882c4dbb to 7ca345011ac4304463197fac0e56eab1bc7e6af0\r\n<details>\r\n<summary>Commits</summary>\r\n<ul>\r\n<li><a href=\"https://github.com/docker/login-action/commit/7ca345011ac4304463197fac0e56eab1bc7e6af0\"><code>7ca3450</code></a> Merge pull request <a href=\"https://redirect.github.com/docker/login-action/issues/806\">#806</a> from docker/dependabot/npm_and_yarn/docker/actions-to...</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/02b671aa021b56f85fa4db2ff82a4de17fe322aa\"><code>02b671a</code></a> build(deps): bump <code>@​docker/actions-toolkit</code> from 0.40.0 to 0.42.0</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/06895751d15a223ec091bea144ad5c7f50d228d0\"><code>0689575</code></a> Merge pull request <a href=\"https://redirect.github.com/docker/login-action/issues/800\">#800</a> from crazy-max/publish-immutable-action</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/02c9ff3be2fc1b56f9ab4494083e97e918fa8089\"><code>02c9ff3</code></a> ci: publish as immutable action workflow</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/5d8785b43a795ee002a17dbf1a2235dc1997224b\"><code>5d8785b</code></a> Merge pull request <a href=\"https://redirect.github.com/docker/login-action/issues/801\">#801</a> from docker/dependabot/npm_and_yarn/docker/actions-to...</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/7a65d3de5dd5fe5ce541c7f166bc0baae6bb2c7a\"><code>7a65d3d</code></a> chore: update generated content</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/bd2f40996ac4b7326bbbfa95159b8445646ba927\"><code>bd2f409</code></a> build(deps): bump <code>@​docker/actions-toolkit</code> from 0.35.0 to 0.40.0</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/9fd0581bf02af9b3a0410347705ef9c24018739b\"><code>9fd0581</code></a> Merge pull request <a href=\"https://redirect.github.com/docker/login-action/issues/791\">#791</a> from docker/dependabot/npm_and_yarn/actions/core-1.11.1</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/eefb7e8744995e77000627dde1a77eeb57c46eda\"><code>eefb7e8</code></a> chore: update generated content</li>\r\n<li><a href=\"https://github.com/docker/login-action/commit/cb13d66af03ce915a78ee6be60c5d85e3d9afc80\"><code>cb13d66</code></a> build(deps): bump <code>@​actions/core</code> from 1.10.1 to 1.11.1</li>\r\n<li>Additional commits viewable in <a href=\"https://github.com/docker/login-action/compare/3d58c274f17dffee475a5520cbe67f0a882c4dbb...7ca345011ac4304463197fac0e56eab1bc7e6af0\">compare view</a></li>\r\n</ul>\r\n</details>\r\n<br />\r\n\r\n\r\nDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.\r\n\r\n[//]: # (dependabot-automerge-start)\r\n[//]: # (dependabot-automerge-end)\r\n\r\n---\r\n\r\n<details>\r\n<summary>Dependabot commands and options</summary>\r\n<br />\r\n\r\nYou can trigger Dependabot actions by commenting on this PR:\r\n- `@dependabot rebase` will rebase this PR\r\n- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it\r\n- `@dependabot merge` will merge this PR after your CI passes on it\r\n- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it\r\n- `@dependabot cancel merge` will cancel a previously requested merge and block automerging\r\n- `@dependabot reopen` will reopen this PR if it is closed\r\n- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually\r\n- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency\r\n- `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself)\r\n- `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself)\r\n- `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself)\r\n- `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency\r\n- `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions\r\n\r\n\r\n</details>",
"head": {
"ref": "bump-changelog-writer"
}
}
}
2 changes: 1 addition & 1 deletion typos.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[files]
extend-exclude = ["src/test_util"]
extend-exclude = ["src/test_util", "test_data"]

0 comments on commit 0ec44a1

Please sign in to comment.