From a20077c9f2cf375246173883984744adcaba7e80 Mon Sep 17 00:00:00 2001 From: thairanaru Date: Tue, 14 Jul 2026 19:46:49 -0700 Subject: [PATCH 1/2] refactor: removed reducdant fn type_action and refactored spelling --- src/input.rs | 76 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/src/input.rs b/src/input.rs index cef7fba..6519d23 100644 --- a/src/input.rs +++ b/src/input.rs @@ -36,22 +36,49 @@ impl Default for InputState { input_mode: InputMode::UI, pending_keys: Vec::with_capacity(2), key_maps: KeyMaps { - ui: [( + ui: HashMap::from([( vec![KeyEvent::new(KeyCode::Char('q'), KeyModifiers::NONE)], Action::Quit, - )] - .into_iter() - .collect(), + )]), normal: HashMap::new(), visual: HashMap::new(), - typing: HashMap::new(), + typing: HashMap::from([ + ( + vec![KeyEvent::new(KeyCode::Backspace, KeyModifiers::NONE)], + Action::RemoveCharacter, + ), + ( + vec![KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)], + Action::Enter, + ), + ( + vec![KeyEvent::new(KeyCode::Left, KeyModifiers::NONE)], + Action::CursorLeft, + ), + ( + vec![KeyEvent::new(KeyCode::Right, KeyModifiers::NONE)], + Action::CursorRight, + ), + ( + vec![KeyEvent::new(KeyCode::Up, KeyModifiers::NONE)], + Action::CursorUp, + ), + ( + vec![KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)], + Action::CursorDown, + ), + ( + vec![KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE)], + Action::Escape, + ), + ]), }, } } } impl InputState { - /// Gets respective keymap based on iinput mode + /// Gets respective keymap based on input mode fn key_map(&self) -> &HashMap, Action> { match self.input_mode { InputMode::UI => &self.key_maps.ui, @@ -74,31 +101,20 @@ impl InputState { pub fn process_key_event(&mut self, key_event: KeyEvent) -> Option { self.pending_keys.push(key_event); let key_map = self.key_map(); - let actions = key_map - .get(&self.pending_keys) - .cloned() - .or_else(|| match self.input_mode { - InputMode::Normal | InputMode::UI | InputMode::Visual => None, - InputMode::Insert | InputMode::Command => type_action(key_event), - }); - if actions.is_some() || !self.has_potential_pending_key_bindings() { + + let action = + key_map + .get(&self.pending_keys) + .cloned() + .or(match (self.input_mode, key_event.code) { + (InputMode::Insert | InputMode::Command, KeyCode::Char(c)) => { + Some(Action::AppendCharacter(c)) + } + _ => None, + }); + if action.is_some() || !self.has_potential_pending_key_bindings() { self.pending_keys.clear(); } - actions - } -} - -/// Turn a key event to their respective action during typing -fn type_action(key_event: KeyEvent) -> Option { - match key_event.code { - KeyCode::Char(c) => Some(Action::AppendCharacter(c)), - KeyCode::Backspace => Some(Action::RemoveCharacter), - KeyCode::Enter => Some(Action::Enter), - KeyCode::Left => Some(Action::CursorLeft), - KeyCode::Right => Some(Action::CursorRight), - KeyCode::Up => Some(Action::CursorUp), - KeyCode::Down => Some(Action::CursorDown), - KeyCode::Esc => Some(Action::Escape), - _ => None, + action } } From 167e88472656ac40c9a4f9f7cbf5ab196ea6b381 Mon Sep 17 00:00:00 2001 From: ih8js-git <141177946+ih8js-git@users.noreply.github.com> Date: Wed, 15 Jul 2026 19:31:50 -0500 Subject: [PATCH 2/2] feat: add input validation and secure JSON payload construction to PR alert workflow --- .github/workflows/pr-alert.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-alert.yml b/.github/workflows/pr-alert.yml index 804ff78..cde1002 100644 --- a/.github/workflows/pr-alert.yml +++ b/.github/workflows/pr-alert.yml @@ -8,7 +8,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Send to Stoat + env: + STOAT_WEBHOOK_URL: ${{ secrets.STOAT_WEBHOOK_URL }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_URL: ${{ github.event.pull_request.html_url }} run: | + if [ -z "$STOAT_WEBHOOK_URL" ]; then + echo "Error: Webhook URL secret is not set." + exit 1 + fi + + # Safely construct JSON payload + PAYLOAD=$(jq -n --arg content "New PR opened: $PR_TITLE\n$PR_URL" '{content: $content}') + curl -X POST -H "Content-Type: application/json" \ - -d '{"content": "New PR opened: ${{ github.event.pull_request.title }}\n${{ github.event.pull_request.html_url }}"}' \ - ${{ secrets.STOAT_WEBHOOK_URL }} + -d "$PAYLOAD" \ + "$STOAT_WEBHOOK_URL" +