git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
31fa85ffe11a1e2fe0c90db28e7545de3f3cf89b blob 2611 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
#!/bin/sh
#
# This is an  example hook script, DO NOT use it on production service.

debug() {
	case "$AGIT_DEBUG" in
	"yes" | "true" | "1")
		;;
	*)
		return
	esac

	echo >&2 "[DEBUG] $@"
}

# Parse push options
if test -n "$GIT_PUSH_OPTION_COUNT"
then
	i=0
	while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"
	do
		eval "value=\$GIT_PUSH_OPTION_$i"
		i=$((i + 1))

		k=$(echo ${value%=*} | tr [a-z] [A-Z])
		v=${value#*=}
		if test -n "$v" && test -n "$k"
		then
			k="AGIT_$k"
		else
			continue
		fi
		eval "$k=$v"
		debug "[proc-receive] push-option: $k=$v"
	done
fi

# Read push commands.
count=0
while read old new refname
do
	debug "[proc-receive] command from stdin: $old $new $refname"
	count=$(( count + 1 ))
	# Only one special refname is allowed for each push
	if test $count -gt 1
	then
		echo >&2 "[proc-receive]: cannot handle more than one push commands"
		exit 1
	fi

	# Parse refname, and set envrionment
	remains=
	if test "${refname#refs/for/}" != "$refname"
	then
		AGIT_PR_IS_DRAFT=false
		remains=${refname#refs/for/}
	elif test "${refname#refs/drafts/}" != "$refname"
	then
		AGIT_PR_IS_DRAFT=true
		remains=${refname#refs/drafts/}
	else
		echo >&2 "[proc-receive] unknown refname: $refname"
		exit 1
	fi

	ref=
	found_ref=
	for i in $(echo $remains | tr "/" "\n")
	do
		if test -z "$ref"
		then
			ref=$i
		else
			ref=$ref/$i
		fi
		if git rev-parse --verify $ref -- 2>/dev/null
		then
			found_ref=yes
			break
		fi
	done
	if test -z "$found_ref"
	then
		echo >&2 "[proc-receive] cannot find target branch from ref: $refname"
		exit 1
	fi
	AGIT_PR_TARGET=$ref
	AGIT_PR_SOURCE=${remains#$ref/}
done

if test -z "$AGIT_PR_TARGET"
then
	echo >&2 "[proc-receive] fail to parse refname, no target found"
	exit 1
fi

# Call API to generate code review.
debug "[proc-receive] call API (AGIT_PR_TARGET=$AGIT_PR_TARGET, AGIT_PR_TOPIC=$AGIT_PR_TOPIC)..."

# Parse result of API.
debug "[proc-receive] parse API result, and get AGIT_PR_ID, etc."
AGIT_PR_ID="12345678901"
AGIT_PR_LOCAL_ID="23"

# Show message.
if test -n "$AGIT_PR_ID"
then
	echo >&2 "[proc-receive] *******************************************************"
	echo >&2 "[proc-receive] * Pull request #$AGIT_PR_ID created/updated           *"
	echo >&2 "[proc-receive] * URL: https://... ...                                *"
	echo >&2 "[proc-receive] *******************************************************"
fi

# Show envs to stdout, and will be exported as envs for "post-receive" hook.
debug "[proc-receive] output kv pairs to stdout for git to parse."
echo "AGIT_PR_ID=$AGIT_PR_ID"
echo "AGIT_PR_LOCAL_ID=$AGIT_PR_LOCAL_ID"

exit 0
debug log:

solving 31fa85ffe1 ...
found 31fa85ffe1 in https://public-inbox.org/git/20200308153816.4690-3-worldhello.net@gmail.com/

applying [1/1] https://public-inbox.org/git/20200308153816.4690-3-worldhello.net@gmail.com/
diff --git a/templates/hooks--proc-receive.sample b/templates/hooks--proc-receive.sample
new file mode 100755
index 0000000000..31fa85ffe1

Checking patch templates/hooks--proc-receive.sample...
Applied patch templates/hooks--proc-receive.sample cleanly.

index at:
100755 31fa85ffe11a1e2fe0c90db28e7545de3f3cf89b	templates/hooks--proc-receive.sample

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).