Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename --branch to --revision #49

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ regularly and useful to understand ``atlas`` at a glance.

pull:
repository: <organization-name>/<repository-name>
branch: <branch-name>
revision: <git-revision>
directory: <repo-directory-name>:<local-dir-name> ...
filter: <pattern> ...
expand_glob: 0
Expand Down Expand Up @@ -96,8 +96,10 @@ regularly and useful to understand ``atlas`` at a glance.
`-r` or `--repository`:
slug of the GitHub repository to pull from. Defaults 'openedx/openedx-translations'.

`-b` or `--branch`:
Branch to pull from. Defaults to 'main'
`-n` or `--revision`:
Git revision to pull from. Currently only branches and tags are supported. Defaults to 'main'.

This option name used to be `-b` or `--branch`. The deprecated name will be removed in a future release.

`-f` or `--filter`:
A comma-separated (or space-separated) list of patterns match files and sub-directories.
Expand Down
62 changes: 33 additions & 29 deletions atlas
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Configuration file:

pull:
repository: <organization-name>/<repository-name>
branch: <branch-name>
revision: <git-revision>
directory: <repo-directory-name>:<local-dir-name> ...
filter: <pattern> ...
expand_glob: 0
Expand Down Expand Up @@ -46,8 +46,10 @@ Options:
\`-r\` or \`--repository\`:
slug of the GitHub repository to pull from. Defaults 'openedx/openedx-translations'.

\`-b\` or \`--branch\`:
Branch to pull from. Defaults to 'main'
\`-n\` or \`--revision\`:
Git revision to pull from. Currently only branches and tags are supported. Defaults to 'main'.

This option name used to be \`-b\` or \`--branch\`. The deprecated name will be removed in a future release.

\`-f\` or \`--filter\`:
A comma-separated (or space-separated) list of patterns match files and sub-directories.
Expand Down Expand Up @@ -92,13 +94,13 @@ parser_definition_pull() {
setup PULL_REST help:usage_pull -- \
"Usage: atlas pull [options...] [directory mappings...]"
msg -- 'Options:'
param CONFIG --config -- "path to alternative atlas.yaml configuration file"
param BRANCH -b --branch -- "A branch of translation files"
param REPOSITORY -r --repository -- "The repository containing translation files"
param FILTER -f --filter -- "List of patterns to select which files and sub-directories to checkout."
flag EXPAND_GLOB -g --expand-glob -- "Expand glob pattern e.g. 'atlas pull translations/*/done' to 'atlas pull translations/DoneXBlock/done' if it exists."
flag VERBOSE -v --verbose -- "verbose output to terminal"
flag SILENT -s --silent -- "no output to terminal"
param CONFIG --config -- "path to alternative atlas.yaml configuration file"
param REPOSITORY -r --repository -- "The repository containing translation files"
param REVISION -n --revision -b --branch -- "A git revision of the repository to pull from. The name --branch is deprecated in favor of --revision."
param FILTER -f --filter -- "List of patterns to select which files and sub-directories to checkout."
flag EXPAND_GLOB -g --expand-glob -- "Expand glob pattern e.g. 'atlas pull translations/*/done' to 'atlas pull translations/DoneXBlock/done' if it exists."
flag VERBOSE -v --verbose -- "verbose output to terminal"
flag SILENT -s --silent -- "no output to terminal"
disp :usage_pull -h --help
}
# @end
Expand Down Expand Up @@ -168,7 +170,7 @@ Configuration file:

pull:
repository: <organization-name>/<repository-name>
branch: <branch-name>
revision: <git-revision>
directory: <repo-directory-name>:<local-dir-name> ...
filter: <pattern> ...
expand_glob: 0
Expand Down Expand Up @@ -197,8 +199,10 @@ Options:
`-r` or `--repository`:
slug of the GitHub repository to pull from. Defaults 'openedx/openedx-translations'.

`-b` or `--branch`:
Branch to pull from. Defaults to 'main'
`-n` or `--revision`:
Git revision to pull from. Currently only branches and tags are supported. Defaults to 'main'.

This option name used to be `-b` or `--branch`. The deprecated name will be removed in a future release.

`-f` or `--filter`:
A comma-separated (or space-separated) list of patterns match files and sub-directories.
Expand Down Expand Up @@ -246,8 +250,8 @@ GETOPTIONSHERE
# Generated by getoptions (BEGIN)
# URL: https://github.com/ko1nksm/getoptions (v3.3.0)
CONFIG=''
BRANCH=''
REPOSITORY=''
REVISION=''
FILTER=''
EXPAND_GLOB=''
VERBOSE=''
Expand All @@ -261,7 +265,7 @@ parse_pull() {
eval 'set -- "${OPTARG%%\=*}" "${OPTARG#*\=}"' ${1+'"$@"'}
;;
--no-*|--without-*) unset OPTARG ;;
-[brf]?*) OPTARG=$1; shift
-[rnbf]?*) OPTARG=$1; shift
eval 'set -- "${OPTARG%"${OPTARG#??}"}" "${OPTARG#??}"' ${1+'"$@"'}
;;
-[gvsh]?*) OPTARG=$1; shift
Expand All @@ -274,15 +278,15 @@ parse_pull() {
OPTARG=$2
CONFIG="$OPTARG"
shift ;;
'-b'|'--branch')
'-r'|'--repository')
[ $# -le 1 ] && set "required" "$1" && break
OPTARG=$2
BRANCH="$OPTARG"
REPOSITORY="$OPTARG"
shift ;;
'-r'|'--repository')
'-n'|'--revision'|'-b'|'--branch')
[ $# -le 1 ] && set "required" "$1" && break
OPTARG=$2
REPOSITORY="$OPTARG"
REVISION="$OPTARG"
shift ;;
'-f'|'--filter')
[ $# -le 1 ] && set "required" "$1" && break
Expand Down Expand Up @@ -337,8 +341,9 @@ cat<<'GETOPTIONSHERE'
Usage: atlas pull [options...] [directory mappings...]
Options:
--config CONFIG path to alternative atlas.yaml configuration file
-b, --branch BRANCH A branch of translation files
-r, --repository REPOSITORY The repository containing translation files
-n, --revision, -b, --branch REVISION
A git revision of the repository to pull from. The name --branch is deprecated in favor of --revision.
-f, --filter FILTER List of patterns to select which files and sub-directories to checkout.
-g, --expand-glob Expand glob pattern e.g. 'atlas pull translations/*/done' to 'atlas pull translations/DoneXBlock/done' if it exists.
-v, --verbose verbose output to terminal
Expand Down Expand Up @@ -384,7 +389,7 @@ set_pull_params() {
else
pull_directory=""
pull_repository="openedx/openedx-translations"
pull_branch="main"
pull_revision="main"
pull_filter=""
pull_expand_glob=""
fi
Expand All @@ -402,9 +407,9 @@ set_pull_params() {
pull_repository=$REPOSITORY
fi

if [ "$BRANCH" ];
if [ "$REVISION" ];
then
pull_branch=$BRANCH
pull_revision=$REVISION
fi

if [ "$FILTER" ];
Expand Down Expand Up @@ -439,7 +444,7 @@ display_pull_params() {
echo "Pulling translation files"
echo " - directory: ${pull_directory:-Not Specified}"
echo " - repository: ${pull_repository:-Not Specified}"
echo " - branch: ${pull_branch:-Not Specified}"
echo " - revision: ${pull_revision:-Not Specified}"
echo " - filter: ${pull_filter:-Not Specified}"
echo " - expand-glob: ${pull_expand_glob:-Not Specified}"
}
Expand Down Expand Up @@ -502,17 +507,16 @@ pull_translations() {
quiet="--quiet"
fi

# use git in quiet mode when verbose isn't set
if [ "$pull_branch" ];
if [ "$pull_revision" ];
then
pull_branch_argument="--branch=${pull_branch}"
pull_revision_argument="--branch=${pull_revision}"
else
pull_branch_argument=""
pull_revision_argument=""
fi

# Creating a shallow clone of the repo without without pulling the files yet
# shellcheck disable=SC2086
git clone $quiet $pull_branch_argument --filter=blob:none --no-checkout --depth=1 \
git clone $quiet $pull_revision_argument --filter=blob:none --no-checkout --depth=1 \
"https://github.com/${pull_repository}.git" translations_TEMP || exit
cd translations_TEMP || exit

Expand Down
2 changes: 1 addition & 1 deletion example.atlas.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pull:
branch: example_branch
revision: example_branch
directory: example_directory
repository: example_repository
filter: example_filter
Expand Down
60 changes: 45 additions & 15 deletions spec/config_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Describe 'Test Default Config'
The line 1 of output should equal 'Pulling translation files'
The line 2 of output should equal ' - directory: Not Specified'
The line 3 of output should equal ' - repository: openedx/openedx-translations'
The line 4 of output should equal ' - branch: main'
The line 4 of output should equal ' - revision: main'
The line 5 of output should equal ' - filter: Not Specified'
The line 6 of output should equal ' - expand-glob: Not Specified'
The variable PULL_TRANSLATIONS_CALLED should equal true
Expand Down Expand Up @@ -60,7 +60,7 @@ Describe 'Test example atlas.yml'
The line 1 of output should equal 'Pulling translation files'
The line 2 of output should equal ' - directory: example_directory'
The line 3 of output should equal ' - repository: example_repository'
The line 4 of output should equal ' - branch: example_branch'
The line 4 of output should equal ' - revision: example_branch'
The line 5 of output should equal ' - filter: example_filter'
The line 6 of output should equal ' - expand-glob: 1'
The variable PULL_TRANSLATIONS_CALLED should equal true
Expand All @@ -83,14 +83,25 @@ Describe 'Test example.atlas.yml'
The line 1 of output should equal 'Pulling translation files'
The line 2 of output should equal ' - directory: example_directory'
The line 3 of output should equal ' - repository: example_repository'
The line 4 of output should equal ' - branch: example_branch'
The line 4 of output should equal ' - revision: example_branch'
The line 5 of output should equal ' - filter: example_filter'
The line 6 of output should equal ' - expand-glob: 1'
The variable PULL_TRANSLATIONS_CALLED should equal true
End
End

Describe 'Test full flags'
Describe 'Test flags'
Parameters
# Long flags with the --revision
"#1" "--repository custom_repository --revision my_revision --expand-glob --filter ar,es_419 positional_arg_directory:mapped_to_dir"
# Long flags with the deprecated --branch flag
"#2" "--repository custom_repository --branch my_revision --expand-glob --filter ar,es_419 positional_arg_directory:mapped_to_dir"
# Short flags with the -n (revision) flag
"#3" "-r custom_repository -n my_revision -g -f ar,es_419 positional_arg_directory:mapped_to_dir"
# Short flags with the deprecated -b (branch) flag
"#4" "-r custom_repository -b my_revision -g -f ar,es_419 positional_arg_directory:mapped_to_dir"
End

# mock pull translations
Intercept begin_pull_translations_mock
__begin_pull_translations_mock__() {
Expand All @@ -100,20 +111,31 @@ Describe 'Test full flags'
}
}

It 'correctly reads full flag params'
When run source ./atlas pull --repository full_flag_repository --branch full_flag_branch --expand-glob --filter ar,es_419 positional_arg_directory:to_dir
It "correctly reads command line flag params test case $1"
When run source ./atlas pull $2 # $2 is set by the Parameters block
The lines of output should equal 6
The line 1 of output should equal 'Pulling translation files'
The line 2 of output should equal ' - directory: positional_arg_directory:to_dir'
The line 3 of output should equal ' - repository: full_flag_repository'
The line 4 of output should equal ' - branch: full_flag_branch'
The line 2 of output should equal ' - directory: positional_arg_directory:mapped_to_dir'
The line 3 of output should equal ' - repository: custom_repository'
The line 4 of output should equal ' - revision: my_revision'
The line 5 of output should equal ' - filter: ar es_419'
The line 6 of output should equal ' - expand-glob: 1'
The variable PULL_TRANSLATIONS_CALLED should equal true
End
End

Describe 'Test short flags'
Describe 'Test flags'
Parameters
# Long flags with the --revision
"#1" "--repository custom_repository --revision my_revision --expand-glob --filter ar,es_419 positional_arg_directory:mapped_to_dir"
# Long flags with the deprecated --branch flag
"#2" "--repository custom_repository --branch my_revision --expand-glob --filter ar,es_419 positional_arg_directory:mapped_to_dir"
# Short flags with the -n (revision) flag
"#3" "-r custom_repository -n my_revision -g -f ar,es_419 positional_arg_directory:mapped_to_dir"
# Short flags with the deprecated -b (branch) flag
"#4" "-r custom_repository -b my_revision -g -f ar,es_419 positional_arg_directory:mapped_to_dir"
End

# mock pull translations
Intercept begin_pull_translations_mock
__begin_pull_translations_mock__() {
Expand All @@ -123,21 +145,21 @@ Describe 'Test short flags'
}
}

It 'correctly reads short flag params'
When run source ./atlas pull -r short_flag_repository -b short_flag_branch -g -f 'ar es_419' positional_arg_directory:mapped_to_dir
It "correctly reads command line flag params test case $1"
When run source ./atlas pull $2 # $2 is set by the Parameters block
The lines of output should equal 6
The line 1 of output should equal 'Pulling translation files'
The line 2 of output should equal ' - directory: positional_arg_directory:mapped_to_dir'
The line 3 of output should equal ' - repository: short_flag_repository'
The line 4 of output should equal ' - branch: short_flag_branch'
The line 3 of output should equal ' - repository: custom_repository'
The line 4 of output should equal ' - revision: my_revision'
The line 5 of output should equal ' - filter: ar es_419'
The line 6 of output should equal ' - expand-glob: 1'
The variable PULL_TRANSLATIONS_CALLED should equal true
End
End


Describe 'Test short flags'
Describe 'Test multiple directories and comma separated filters'
# mock pull translations
Intercept begin_pull_translations_mock
__begin_pull_translations_mock__() {
Expand All @@ -156,4 +178,12 @@ Describe 'Test short flags'
The line 2 of output should equal ' - directory: orange_dir:foo_local_dir blue_dir:bazz_local_dir'
The variable PULL_TRANSLATIONS_CALLED should equal true
End


It 'correctly reads multiple directories and separate them in spaces'
When run source ./atlas pull -r short_flag_repository -f ar,de_DE orange_dir:foo_local_dir
The lines of output should equal 6
The line 5 of output should equal ' - filter: ar de_DE' # Convert comma separated into space-separated shell array
The variable PULL_TRANSLATIONS_CALLED should equal true
End
End
8 changes: 4 additions & 4 deletions spec/integration_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ Describe 'Pull performance on edX Platform Arabic translations'

It 'calls everything properly'
TEST_START_TIME=$(date +%s) # Time the bash script
When run source $PREVIOUS_PWD/atlas pull -r openedx/xblock-drag-and-drop-v2 -b v3.2.0 -f ar,fr drag_and_drop_v2:drag_and_drop_v2 non-existent-dir:no-files-here
When run source $PREVIOUS_PWD/atlas pull -r openedx/xblock-drag-and-drop-v2 -n v3.2.0 -f ar,fr drag_and_drop_v2:drag_and_drop_v2 non-existent-dir:no-files-here
Assert check_call_time "Pull xblock-drag-and-drop-v2" $TEST_START_TIME 60 # Allow a maximum of 60 seconds

The output should equal 'Pulling translation files
- directory: drag_and_drop_v2:drag_and_drop_v2 non-existent-dir:no-files-here
- repository: openedx/xblock-drag-and-drop-v2
- branch: v3.2.0
- revision: v3.2.0
- filter: ar fr
- expand-glob: Not Specified
Creating a temporary Git repository to pull translations into "./translations_TEMP"...
Expand Down Expand Up @@ -100,13 +100,13 @@ Describe 'Bash glob patterns'

It 'pulls with glob patterns'
TEST_START_TIME=$(date +%s) # Time the bash script
When run source $PREVIOUS_PWD/atlas pull -r openedx/xblock-drag-and-drop-v2 -b v3.2.0 --expand-glob -f ar 'drag_and_drop_v2/*/locale:drag_and_drop_v2'
When run source $PREVIOUS_PWD/atlas pull -r openedx/xblock-drag-and-drop-v2 -n v3.2.0 --expand-glob -f ar 'drag_and_drop_v2/*/locale:drag_and_drop_v2'
Assert check_call_time "Pull xblock-drag-and-drop-v2" $TEST_START_TIME 60 # Allow a maximum of 60 seconds

The output should equal 'Pulling translation files
- directory: drag_and_drop_v2/*/locale:drag_and_drop_v2
- repository: openedx/xblock-drag-and-drop-v2
- branch: v3.2.0
- revision: v3.2.0
- filter: ar
- expand-glob: 1
Creating a temporary Git repository to pull translations into "./translations_TEMP"...
Expand Down
4 changes: 2 additions & 2 deletions spec/pull_performance_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ Describe 'Pull performance on edX Platform Arabic translations'

It 'calls everything properly'
TEST_START_TIME=$(date +%s) # Time the bash script
When run source $PREVIOUS_PWD/atlas pull -r openedx/edx-platform -b open-release/nutmeg.1 -f ar,fr conf/locale:messages non-existent-dir:no-files-here
When run source $PREVIOUS_PWD/atlas pull -r openedx/edx-platform -n open-release/nutmeg.1 -f ar,fr conf/locale:messages non-existent-dir:no-files-here
Assert check_call_time "Pull edX Platform" $TEST_START_TIME 10 # Allow a maximum of 10 seconds

The output should equal 'Pulling translation files
- directory: conf/locale:messages non-existent-dir:no-files-here
- repository: openedx/edx-platform
- branch: open-release/nutmeg.1
- revision: open-release/nutmeg.1
- filter: ar fr
- expand-glob: Not Specified
Creating a temporary Git repository to pull translations into "./translations_TEMP"...
Expand Down
Loading