diff --git a/integrations/api_pull_commits_test.go b/integrations/api_pull_commits_test.go new file mode 100644 index 0000000000000..db073da734aa3 --- /dev/null +++ b/integrations/api_pull_commits_test.go @@ -0,0 +1,75 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package integrations + +import ( + "net/http" + "testing" + + "code.gitea.io/gitea/models" + api "code.gitea.io/gitea/modules/structs" + "github.com/stretchr/testify/assert" +) + +func TestAPIPullCommits(t *testing.T) { + defer prepareTestEnv(t)() + pullIssue := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 6}).(*models.PullRequest) + assert.NoError(t, pullIssue.LoadIssue()) + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository) + + // test ListPullReviews + session := loginUser(t, "user2") + req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index) + resp := session.MakeRequest(t, req, http.StatusOK) + + var commits []*api.Commit + DecodeJSON(t, resp, &commits) + if !assert.Len(t, commits, 3) { + return + } + assert.Equal(t, "c711aebdd140cebd540469c0de87960457a0ab81", commits[0].SHA) + assert.Equal(t, "f6211fabb4e7f31f76b64dda1aa8545ff7eb2e78", commits[1].SHA) + assert.Equal(t, "443bb80f40ada270ea0d8b9df4ce7f1173a5748a", commits[2].SHA) +} + +func TestAPIMergedPullCommits(t *testing.T) { + defer prepareTestEnv(t)() + pullIssue := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 7}).(*models.PullRequest) + assert.NoError(t, pullIssue.LoadIssue()) + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository) + + // test ListPullReviews + session := loginUser(t, "user2") + req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index) + resp := session.MakeRequest(t, req, http.StatusOK) + + var commits []*api.Commit + DecodeJSON(t, resp, &commits) + if !assert.Len(t, commits, 2) { + return + } + assert.Equal(t, "e3dfaeb234e2a4570875ea3be7cedaebf350d703", commits[0].SHA) + assert.Equal(t, "a20333be2715060c61c8d0268c4f622bde1ae4ac", commits[1].SHA) +} + +func TestAPIClosedPullCommits(t *testing.T) { + defer prepareTestEnv(t)() + pullIssue := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 8}).(*models.PullRequest) + assert.NoError(t, pullIssue.LoadIssue()) + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository) + + // test ListPullReviews + session := loginUser(t, "user2") + req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index) + resp := session.MakeRequest(t, req, http.StatusOK) + + var commits []*api.Commit + DecodeJSON(t, resp, &commits) + if !assert.Len(t, commits, 2) { + return + } + assert.Equal(t, "f611a4c2dc1894ebbe5e8b558b4055169506048b", commits[0].SHA) + assert.Equal(t, "e1adcf142a07305ebf40590a41b1a279486759db", commits[1].SHA) +} diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/FETCH_HEAD b/integrations/gitea-repositories-meta/user2/pr_repo.git/FETCH_HEAD new file mode 100644 index 0000000000000..85e186d580052 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/FETCH_HEAD @@ -0,0 +1 @@ +71ef50ba32849b9b7b4d8c98dd98f5a68134c62f branch 'master' of C:\other\gitea-repositories\user2\pr_repo diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/HEAD b/integrations/gitea-repositories-meta/user2/pr_repo.git/HEAD new file mode 100644 index 0000000000000..cb089cd89a7d7 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/config b/integrations/gitea-repositories-meta/user2/pr_repo.git/config new file mode 100644 index 0000000000000..64280b806c976 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = false + bare = true + symlinks = false + ignorecase = true diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/description b/integrations/gitea-repositories-meta/user2/pr_repo.git/description new file mode 100644 index 0000000000000..498b267a8c781 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/applypatch-msg.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/applypatch-msg.sample new file mode 100644 index 0000000000000..a5d7b84a67345 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/commit-msg.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/commit-msg.sample new file mode 100644 index 0000000000000..b58d1184a9d43 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/fsmonitor-watchman.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/fsmonitor-watchman.sample new file mode 100644 index 0000000000000..e673bb3980f3c --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/fsmonitor-watchman.sample @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 1) and a time in nanoseconds +# formatted as a string and outputs to stdout all files that have been +# modified since the given time. Paths must be relative to the root of +# the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $time) = @ARGV; + +# Check the hook interface version + +if ($version == 1) { + # convert nanoseconds to seconds + $time = int $time / 1000000000; +} else { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree; +if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $git_work_tree = Win32::GetCwd(); + $git_work_tree =~ tr/\\/\//; +} else { + require Cwd; + $git_work_tree = Cwd::cwd(); +} + +my $retry = 1; + +launch_watchman(); + +sub launch_watchman { + + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $time but were not transient (ie created after + # $time but no longer exist). + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + # + # The category of transient files that we want to ignore will have a + # creation clock (cclock) newer than $time_t value and will also not + # currently exist. + + my $query = <<" END"; + ["query", "$git_work_tree", { + "since": $time, + "fields": ["name"], + "expression": ["not", ["allof", ["since", $time, "cclock"], ["not", "exists"]]] + }] + END + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + my $json_pkg; + eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; + } or do { + require JSON::PP; + $json_pkg = "JSON::PP"; + }; + + my $o = $json_pkg->new->utf8->decode($response); + + if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { + print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; + $retry--; + qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + print "/\0"; + eval { launch_watchman() }; + exit 0; + } + + die "Watchman: $o->{error}.\n" . + "Falling back to scanning...\n" if $o->{error}; + + binmode STDOUT, ":utf8"; + local $, = "\0"; + print @{$o->{files}}; +} diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive new file mode 100644 index 0000000000000..f1f2709dddeea --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +data=$(cat) +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0)} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do +test -x "${hook}" && test -f "${hook}" || continue +echo "${data}" | "${hook}" +exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do +[ ${i} -eq 0 ] || exit ${i} +done diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive.d/gitea b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive.d/gitea new file mode 100644 index 0000000000000..bc7fb0a76a319 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive.d/gitea @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +"C:/other/gitea/gitea.exe" hook --config='C:/other/gitea/custom/conf/app.ini' post-receive diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-update.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-update.sample new file mode 100644 index 0000000000000..ec17ec1939b7c --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-applypatch.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-applypatch.sample new file mode 100644 index 0000000000000..4142082bcb939 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-commit.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-commit.sample new file mode 100644 index 0000000000000..6a756416384c2 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-push.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-push.sample new file mode 100644 index 0000000000000..6187dbf4390fc --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +z40=0000000000000000000000000000000000000000 + +while read local_ref local_sha remote_ref remote_sha +do + if [ "$local_sha" = $z40 ] + then + # Handle delete + : + else + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Check for WIP commit + commit=`git rev-list -n 1 --grep '^WIP' "$range"` + if [ -n "$commit" ] + then + echo >&2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-rebase.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-rebase.sample new file mode 100644 index 0000000000000..6cbef5c370d8c --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive new file mode 100644 index 0000000000000..f1f2709dddeea --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +data=$(cat) +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0)} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do +test -x "${hook}" && test -f "${hook}" || continue +echo "${data}" | "${hook}" +exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do +[ ${i} -eq 0 ] || exit ${i} +done diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.d/gitea b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.d/gitea new file mode 100644 index 0000000000000..abf00a79ea9b2 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.d/gitea @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +"C:/other/gitea/gitea.exe" hook --config='C:/other/gitea/custom/conf/app.ini' pre-receive diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.sample new file mode 100644 index 0000000000000..a1fd29ec14823 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +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" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/prepare-commit-msg.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/prepare-commit-msg.sample new file mode 100644 index 0000000000000..10fa14c5ab013 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/prepare-commit-msg.sample @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update new file mode 100644 index 0000000000000..df5bd27f106f2 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0)} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do +test -x "${hook}" && test -f "${hook}" || continue +"${hook}" $1 $2 $3 +exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do +[ ${i} -eq 0 ] || exit ${i} +done diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.d/gitea b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.d/gitea new file mode 100644 index 0000000000000..79c2d208a2e38 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.d/gitea @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +"C:/other/gitea/gitea.exe" hook --config='C:/other/gitea/custom/conf/app.ini' update $1 $2 $3 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.sample new file mode 100644 index 0000000000000..80ba94135cc37 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.sample @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --bool hooks.allowunannotated) +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +denycreatebranch=$(git config --bool hooks.denycreatebranch) +allowdeletetag=$(git config --bool hooks.allowdeletetag) +allowmodifytag=$(git config --bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero="0000000000000000000000000000000000000000" +if [ "$newrev" = "$zero" ]; then + newrev_type=delete +else + newrev_type=$(git cat-file -t $newrev) +fi + +case "$refname","$newrev_type" in + refs/tags/*,commit) + # un-annotated tag + short_refname=${refname##refs/tags/} + if [ "$allowunannotated" != "true" ]; then + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/info/exclude b/integrations/gitea-repositories-meta/user2/pr_repo.git/info/exclude new file mode 100644 index 0000000000000..a5196d1be8fb5 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/info/refs b/integrations/gitea-repositories-meta/user2/pr_repo.git/info/refs new file mode 100644 index 0000000000000..e437b259af60b --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/info/refs @@ -0,0 +1,7 @@ +0713475aeb24731bf654b5ffb2b0249e9eab6990 refs/heads/closed_pr +71ef50ba32849b9b7b4d8c98dd98f5a68134c62f refs/heads/master +2055bdadcecdb500439ac40d578d22bae519bbd5 refs/heads/merged_pr +c711aebdd140cebd540469c0de87960457a0ab81 refs/heads/open_pr +c711aebdd140cebd540469c0de87960457a0ab81 refs/pull/1/head +e3dfaeb234e2a4570875ea3be7cedaebf350d703 refs/pull/2/head +f611a4c2dc1894ebbe5e8b558b4055169506048b refs/pull/3/head diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/07/13475aeb24731bf654b5ffb2b0249e9eab6990 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/07/13475aeb24731bf654b5ffb2b0249e9eab6990 new file mode 100644 index 0000000000000..6f3bedbad9e11 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/07/13475aeb24731bf654b5ffb2b0249e9eab6990 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/0a/2d4136a3bddf08e911a3ec15084ba40854e0a9 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/0a/2d4136a3bddf08e911a3ec15084ba40854e0a9 new file mode 100644 index 0000000000000..a250c46c313a7 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/0a/2d4136a3bddf08e911a3ec15084ba40854e0a9 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/20/55bdadcecdb500439ac40d578d22bae519bbd5 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/20/55bdadcecdb500439ac40d578d22bae519bbd5 new file mode 100644 index 0000000000000..9cbcb664294cb --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/20/55bdadcecdb500439ac40d578d22bae519bbd5 @@ -0,0 +1,3 @@ +x[ +0E*fi&Dԝ$ L#mDpmKCkiOьYŁKY65cPE%h\`]Hxsq:^5X56?,˙a^ +TإQ>Pr?fHlAB|zKih"6\NܢF-t \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/42fd4bde301c8762baafb8c9b77b56aa63bc48 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/42fd4bde301c8762baafb8c9b77b56aa63bc48 new file mode 100644 index 0000000000000..1977977699ac4 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/42fd4bde301c8762baafb8c9b77b56aa63bc48 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/63ac63a3e121ef77e8f046c8521d77a7171d35 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/63ac63a3e121ef77e8f046c8521d77a7171d35 new file mode 100644 index 0000000000000..01b10a408cfaf Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/63ac63a3e121ef77e8f046c8521d77a7171d35 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/a2/0333be2715060c61c8d0268c4f622bde1ae4ac b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/a2/0333be2715060c61c8d0268c4f622bde1ae4ac new file mode 100644 index 0000000000000..cff255e56fb08 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/a2/0333be2715060c61c8d0268c4f622bde1ae4ac differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/b1/715a6bdacfab4bbfa6c7a58f970b7ca7476b20 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/b1/715a6bdacfab4bbfa6c7a58f970b7ca7476b20 new file mode 100644 index 0000000000000..8fcc8c0d98cd3 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/b1/715a6bdacfab4bbfa6c7a58f970b7ca7476b20 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/c2/e48d686876138b9a5ba7f260d3827a208409fa b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/c2/e48d686876138b9a5ba7f260d3827a208409fa new file mode 100644 index 0000000000000..75c4a13ae405b --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/c2/e48d686876138b9a5ba7f260d3827a208409fa @@ -0,0 +1 @@ +xM mӂ1a ؾx`2s^eF7bY! 4R%gѴRdr([BNRb(g(;meߟ H7 \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/c7/11aebdd140cebd540469c0de87960457a0ab81 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/c7/11aebdd140cebd540469c0de87960457a0ab81 new file mode 100644 index 0000000000000..b8a54be9b99a3 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/c7/11aebdd140cebd540469c0de87960457a0ab81 @@ -0,0 +1,2 @@ +x[ +0E*f$G"N2 4"zKq~pS穃p ]LQŐ%SJV5DIK)xKR%Uy[gG_^\ 7GSq/3/|ek1h8J#v__P|FM \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d0/b367de3c539d0d37e0c1b1acaf90c83c66aad4 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d0/b367de3c539d0d37e0c1b1acaf90c83c66aad4 new file mode 100644 index 0000000000000..da3cc7575f542 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d0/b367de3c539d0d37e0c1b1acaf90c83c66aad4 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d2/44ac23bcd16c640ff10e29f70cb9c79c928c56 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d2/44ac23bcd16c640ff10e29f70cb9c79c928c56 new file mode 100644 index 0000000000000..76c03e7bc7c58 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d2/44ac23bcd16c640ff10e29f70cb9c79c928c56 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/dd/9b2bfb61431f03357972975ae8b0c68c6770df b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/dd/9b2bfb61431f03357972975ae8b0c68c6770df new file mode 100644 index 0000000000000..222ffd55458e5 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/dd/9b2bfb61431f03357972975ae8b0c68c6770df @@ -0,0 +1 @@ +x- 0D=[.@pݐl07iXϫ-~=cÂ^,凛^ ZCy" \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e1/adcf142a07305ebf40590a41b1a279486759db b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e1/adcf142a07305ebf40590a41b1a279486759db new file mode 100644 index 0000000000000..e3bf8f4c79ae9 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e1/adcf142a07305ebf40590a41b1a279486759db @@ -0,0 +1,3 @@ +xQ +0D)Mi dl`i#oͤ2McPU)̃h5XC^sRd:m\f2s0(#N( +a(ȫ9/~#Ivl㎗uIMe:ö;8"!6[]g|@LG \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e3/dfaeb234e2a4570875ea3be7cedaebf350d703 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e3/dfaeb234e2a4570875ea3be7cedaebf350d703 new file mode 100644 index 0000000000000..743711066ff58 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e3/dfaeb234e2a4570875ea3be7cedaebf350d703 @@ -0,0 +1,2 @@ +xQ +0)tIZQol`i#o 2Mct. I:ۦ.AKsp3O^ths[oMaeK4ĭӲ'ïz/ \n) 'ޱ/먓ktDpdv__|M \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 new file mode 100644 index 0000000000000..711223894375f Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f3/5a7427dd78d730782bc51d73be2d919ca35810 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f3/5a7427dd78d730782bc51d73be2d919ca35810 new file mode 100644 index 0000000000000..12d278742820f Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f3/5a7427dd78d730782bc51d73be2d919ca35810 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/11a4c2dc1894ebbe5e8b558b4055169506048b b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/11a4c2dc1894ebbe5e8b558b4055169506048b new file mode 100644 index 0000000000000..cb52e32b2a299 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/11a4c2dc1894ebbe5e8b558b4055169506048b @@ -0,0 +1,2 @@ +x[ +0E*f<&IDԝ1m$R܁=Ty zc]F5)]E;/aI/XB7r,یd@UОptR"6.n wϼC%y8JRlvȯZ|K \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/211fabb4e7f31f76b64dda1aa8545ff7eb2e78 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/211fabb4e7f31f76b64dda1aa8545ff7eb2e78 new file mode 100644 index 0000000000000..0471fb2e3300a Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/211fabb4e7f31f76b64dda1aa8545ff7eb2e78 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/3107991a7971d7953be3b96d735cafc576620b b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/3107991a7971d7953be3b96d735cafc576620b new file mode 100644 index 0000000000000..78cb1e0e6bfb4 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/3107991a7971d7953be3b96d735cafc576620b differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f9/3e3a1a1525fb5b91020da86e44810c87a2d7bc b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f9/3e3a1a1525fb5b91020da86e44810c87a2d7bc new file mode 100644 index 0000000000000..91fccd447fe1a Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f9/3e3a1a1525fb5b91020da86e44810c87a2d7bc differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/fe/78eda57d408e7c7f44e97ed68a2213c9ba63e9 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/fe/78eda57d408e7c7f44e97ed68a2213c9ba63e9 new file mode 100644 index 0000000000000..7f4adaba6625f --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/fe/78eda57d408e7c7f44e97ed68a2213c9ba63e9 @@ -0,0 +1 @@ +x- D=[ŔG0V\kl_$&3=ɎyZ-rEeBhf.ޮ%FJ3#'9~l=JڻrI($ \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/3bd934908fed79bfd11cc3c1edaeec694a58d2 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/3bd934908fed79bfd11cc3c1edaeec694a58d2 new file mode 100644 index 0000000000000..04b7b4389028c Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/3bd934908fed79bfd11cc3c1edaeec694a58d2 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/f2d8fe1b36ec3ababaa45266ea4bcfda303858 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/f2d8fe1b36ec3ababaa45266ea4bcfda303858 new file mode 100644 index 0000000000000..f59c9f97665d1 Binary files /dev/null and b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/f2d8fe1b36ec3ababaa45266ea4bcfda303858 differ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/info/packs b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/info/packs new file mode 100644 index 0000000000000..8b137891791fe --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/info/packs @@ -0,0 +1 @@ + diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/packed-refs b/integrations/gitea-repositories-meta/user2/pr_repo.git/packed-refs new file mode 100644 index 0000000000000..250f187384963 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/packed-refs @@ -0,0 +1 @@ +# pack-refs with: peeled fully-peeled sorted diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/closed_pr b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/closed_pr new file mode 100644 index 0000000000000..c39fc8f7bc584 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/closed_pr @@ -0,0 +1 @@ +0713475aeb24731bf654b5ffb2b0249e9eab6990 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/master b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/master new file mode 100644 index 0000000000000..e86360d99dccb --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/master @@ -0,0 +1 @@ +71ef50ba32849b9b7b4d8c98dd98f5a68134c62f diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/merged_pr b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/merged_pr new file mode 100644 index 0000000000000..f425a406864a5 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/merged_pr @@ -0,0 +1 @@ +2055bdadcecdb500439ac40d578d22bae519bbd5 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/open_pr b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/open_pr new file mode 100644 index 0000000000000..61f6ae0fd2900 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/open_pr @@ -0,0 +1 @@ +c711aebdd140cebd540469c0de87960457a0ab81 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/1/head b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/1/head new file mode 100644 index 0000000000000..61f6ae0fd2900 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/1/head @@ -0,0 +1 @@ +c711aebdd140cebd540469c0de87960457a0ab81 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/2/head b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/2/head new file mode 100644 index 0000000000000..9a8eb338e1bd5 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/2/head @@ -0,0 +1 @@ +e3dfaeb234e2a4570875ea3be7cedaebf350d703 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/3/head b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/3/head new file mode 100644 index 0000000000000..a16e3f2b2c4df --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/3/head @@ -0,0 +1 @@ +f611a4c2dc1894ebbe5e8b558b4055169506048b diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 39a96dc550338..ae15b4976751b 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -135,3 +135,39 @@ is_pull: true created_unix: 1579194806 updated_unix: 1579194806 + +- + id: 12 + repo_id: 49 + index: 1 + poster_id: 1 + name: open_pr + content: PR that stays open + is_closed: false + is_pull: true + created_unix: 1593455366 + updated_unix: 1593455423 + +- + id: 13 + repo_id: 49 + index: 2 + poster_id: 1 + name: merged_pr + content: PR that gets merged + is_closed: true + is_pull: true + created_unix: 1593455608 + updated_unix: 1593455740 + +- + id: 14 + repo_id: 49 + index: 3 + poster_id: 1 + name: closed_pr + content: PR that gest closed without merging + is_closed: true + is_pull: true + created_unix: 1593455962 + updated_unix: 1593456141 \ No newline at end of file diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index b555da83ef762..0d0fe9245759c 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -63,3 +63,42 @@ base_branch: branch1 merge_base: 1234567890abcdef has_merged: false + +- + id: 6 + type: 0 + status: 0 + issue_id: 12 + index: 1 + head_repo_id: 49 + base_repo_id: 49 + head_branch: open_pr + base_branch: master + merge_base: 0a2d4136a3bddf08e911a3ec15084ba40854e0a9 + has_merged: false + +- + id: 7 + type: 0 + status: 3 + issue_id: 13 + index: 2 + head_repo_id: 49 + base_repo_id: 49 + head_branch: merged_pr + base_branch: master + merge_base: 0a2d4136a3bddf08e911a3ec15084ba40854e0a9 + has_merged: true + +- + id: 8 + type: 0 + status: 0 + issue_id: 14 + index: 3 + head_repo_id: 49 + base_repo_id: 49 + head_branch: closed_pr + base_branch: master + merge_base: 0a2d4136a3bddf08e911a3ec15084ba40854e0a9 + has_merged: false \ No newline at end of file diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 35b9b92b79525..bb99dea71bb71 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -514,3 +514,17 @@ type: 3 config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}" created_unix: 946684810 + +- + id: 75 + repo_id: 49 + type: 1 + config: "{}" + created_unix: 946684810 + +- + id: 76 + repo_id: 49 + type: 3 + config: "{}" + created_unix: 946684810 \ No newline at end of file diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 3b86dd0f81f91..eab1d62aa72a1 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -674,3 +674,18 @@ num_pulls: 1 is_mirror: false status: 0 + +- + id: 49 + owner_id: 2 + owner_name: user2 + lower_name: pr_repo + name: pr_repo + is_private: false + num_stars: 0 + num_forks: 0 + num_issues: 0 + num_pulls: 3 + num_closed_pulls: 2 + is_mirror: false + status: 0 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 640fd65bffec1..ebacd2ec0497d 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -30,7 +30,7 @@ is_admin: false avatar: avatar2 avatar_email: user2@example.com - num_repos: 9 + num_repos: 10 num_stars: 2 num_followers: 2 num_following: 1 diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 0567c3560c782..548fb307e1fdd 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -813,7 +813,7 @@ func RegisterRoutes(m *macaron.Macaron) { Get(repo.GetPullReviewComments) }) }) - + m.Get("/commits", repo.GetPullRequestCommits) }) }, mustAllowPulls, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(false)) m.Group("/statuses", func() { diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 5acbb9e29709f..035f1d91d61f0 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -6,7 +6,9 @@ package repo import ( "fmt" + "math" "net/http" + "strconv" "strings" "time" @@ -842,6 +844,117 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) { ctx.Status(http.StatusOK) } +// GetPullRequestCommits gets all commits associated with a given PR +func GetPullRequestCommits(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/pulls/{index}/commits repository repoGetPullRequestCommits + // --- + // summary: Get commits for a pull request + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: index + // in: path + // description: index of the pull request to get + // type: integer + // format: int64 + // required: true + // - name: page + // in: query + // description: page number of results to return (1-based) + // type: integer + // - name: limit + // in: query + // description: page size of results, maximum page size is 50 + // type: integer + // responses: + // "200": + // "$ref": "#/responses/CommitList" + // "404": + // "$ref": "#/responses/notFound" + + pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + if err != nil { + if models.IsErrPullRequestNotExist(err) { + ctx.NotFound() + } else { + ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err) + } + return + } + + if err := pr.LoadBaseRepo(); err != nil { + ctx.InternalServerError(err) + return + } + + var prInfo *git.CompareInfo + baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath()) + if err != nil { + ctx.ServerError("OpenRepository", err) + return + } + defer baseGitRepo.Close() + if pr.HasMerged { + prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName()) + } else { + prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName()) + } + if err != nil { + ctx.ServerError("GetCompareInfo", err) + return + } + commits := prInfo.Commits + + listOptions := utils.GetListOptions(ctx) + if listOptions.Page <= 0 { + listOptions.Page = 1 + } + + if listOptions.PageSize > git.CommitsRangeSize { + listOptions.PageSize = git.CommitsRangeSize + } + + commitsCount := commits.Len() + pageCount := int(math.Ceil(float64(commitsCount) / float64(listOptions.PageSize))) + + userCache := make(map[string]*models.User) + + apiCommits := make([]*api.Commit, commits.Len()) + + i := 0 + for commitPointer := commits.Front(); commitPointer != nil; commitPointer = commitPointer.Next() { + commit := commitPointer.Value.(*git.Commit) + + // Create json struct + apiCommits[i], err = toCommit(ctx, ctx.Repo.Repository, commit, userCache) + if err != nil { + ctx.ServerError("toCommit", err) + return + } + + i++ + } + + ctx.SetLinkHeader(int(commitsCount), listOptions.PageSize) + + ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page)) + ctx.Header().Set("X-PerPage", strconv.Itoa(listOptions.PageSize)) + ctx.Header().Set("X-Total", strconv.FormatInt(int64(commitsCount), 10)) + ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount)) + ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < pageCount)) + ctx.JSON(http.StatusOK, &apiCommits) +} + func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*models.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) { baseRepo := ctx.Repo.Repository diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index bf011285f81f5..af40edd5d1262 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -6776,6 +6776,62 @@ } } }, + "/repos/{owner}/{repo}/pulls/{index}/commits": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Get commits for a pull request", + "operationId": "repoGetPullRequestCommits", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "format": "int64", + "description": "index of the pull request to get", + "name": "index", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results, maximum page size is 50", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/CommitList" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, "/repos/{owner}/{repo}/pulls/{index}/merge": { "get": { "produces": [