Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbdf2a22

Browse files
committed
scripts/traiage.sh: add option to commit and push
1 parentd2455fd commitbdf2a22

File tree

1 file changed

+69
-12
lines changed

1 file changed

+69
-12
lines changed

‎scripts/traiage.sh‎

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ source "${SCRIPT_DIR}/lib.sh"
77
CODER_BIN=${CODER_BIN:-"$(which coder)"}
88
AGENTAPI_SLUG=${AGENTAPI_SLUG:-""}
99

10+
TEMPDIR=$(mktemp -d)
11+
trap'rm -rfv "${TEMPDIR}"' EXIT
12+
1013
[[-n${VERBOSE:-} ]]&&set -x
1114
set -euo pipefail
1215

@@ -36,30 +39,40 @@ prompt() {
3639
fi
3740
}
3841

39-
prompt_ssh() {
40-
requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME PROMPT
42+
ssh_config() {
43+
requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME
4144

42-
# For sanity, use OpenSSH with coder config-ssh.
43-
OPENSSH_CONFIG_FILE=/tmp/coder-ssh.config
45+
if [[-n"${OPENSSH_CONFIG_FILE:-}" ]];then
46+
echo"Using existing SSH config file:${OPENSSH_CONFIG_FILE}"
47+
return
48+
fi
49+
50+
OPENSSH_CONFIG_FILE="${TEMPDIR}/coder-ssh.config"
4451
"${CODER_BIN}" \
4552
config-ssh \
4653
--url"${CODER_URL}" \
4754
--token"${CODER_SESSION_TOKEN}" \
4855
--ssh-config-file="${OPENSSH_CONFIG_FILE}" \
4956
--yes
50-
trap'rm -f /tmp/coder-ssh.config' EXIT
57+
export OPENSSH_CONFIG_FILE
58+
}
59+
60+
prompt_ssh() {
61+
requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME PROMPT
62+
63+
ssh_config
5164

5265
# Write prompt to a file in the workspace
53-
ssh \
54-
-F /tmp/coder-ssh.config \
55-
"${WORKSPACE_NAME}.coder" \
56-
-- \
57-
"cat >/tmp/prompt.txt"<<<"${PROMPT}"
66+
cat<<<"${PROMPT}">"${TEMPDIR}/prompt.txt"
67+
scp \
68+
-F"${OPENSSH_CONFIG_FILE}" \
69+
"${TEMPDIR}/prompt.txt" \
70+
"${WORKSPACE_NAME}.coder:/tmp/prompt.txt"
5871

5972
# Execute claude over SSH
6073
# Note: use of cat to work around claude-code#7357
6174
ssh \
62-
-F/tmp/coder-ssh.config \
75+
-F"${OPENSSH_CONFIG_FILE}" \
6376
"${WORKSPACE_NAME}.coder" \
6477
-- \
6578
"cat /tmp/prompt.txt |\"\${HOME}\"/.local/bin/claude --dangerously-skip-permissions --print --verbose --output-format=stream-json"
@@ -139,7 +152,8 @@ wait() {
139152

140153
archive() {
141154
requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME
142-
echo"Not implemented yet!"
155+
156+
ssh_config
143157
exit 0
144158
"${CODER_BIN}" \
145159
--url"${CODER_URL}" \
@@ -148,6 +162,46 @@ archive() {
148162
exit 0
149163
}
150164

165+
commit_push() {
166+
requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME
167+
ssh_config
168+
169+
# For multiple commands, upload a script and run it.
170+
cat>"${TEMPDIR}/commit_push.sh"<<-EOF
171+
#!/usr/bin/env bash
172+
set -euo pipefail
173+
if [[\$(git branch --show-current) != "${WORKSPACE_NAME}" ]]; then
174+
git checkout -b${WORKSPACE_NAME}
175+
fi
176+
177+
if [[ -z\$(git status --porcelain) ]]; then
178+
echo "FATAL: No changes to commit"
179+
exit 1
180+
fi
181+
182+
git add -A
183+
commit_msg=\$(echo -n 'You are a CLI utility that generates a commit message. Generate a concise git commit message for the currently staged changes. Print ONLY the commit message and nothing else.' |\${HOME}/.local/bin/claude --print)
184+
if [[ -z "\${commit_msg}" ]]; then
185+
commit_msg="Default commit message"
186+
fi
187+
git commit -am "\${commit_msg}"
188+
git push origin${WORKSPACE_NAME}
189+
EOF
190+
191+
scp \
192+
-F"${OPENSSH_CONFIG_FILE}" \
193+
"${TEMPDIR}/commit_push.sh" \
194+
"${WORKSPACE_NAME}.coder:/tmp/commit_push.sh"
195+
196+
ssh \
197+
-F"${OPENSSH_CONFIG_FILE}" \
198+
"${WORKSPACE_NAME}.coder" \
199+
-- \
200+
"chmod +x /tmp/commit_push.sh && /tmp/commit_push.sh"
201+
202+
exit$?
203+
}
204+
151205
delete() {
152206
requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME
153207
"${CODER_BIN}" \
@@ -176,6 +230,9 @@ main() {
176230
archive)
177231
archive
178232
;;
233+
commit-push)
234+
commit_push
235+
;;
179236
delete)
180237
delete
181238
;;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp