%global revision_date 20180514
%global git_short_version_hash 733ac805
%global git_full_version_hash 733ac805016203a38cf7ee1b8712e823aafc8033
%global ver_months_ahead %{?epoch:%{epoch}:}0.20180815
%global ver_months_behind %{?epoch:%{epoch}:}0.20180210

Summary:    A command line interface to Phabricator
Name:       arcanist

# copr isn't purging older builds, even though they are deleted
Epoch:      1

Version:    0.%{revision_date}.git%{git_short_version_hash}
Release:    2%{?dist}

License:    ASL 2.0
URL:        https://secure.phabricator.com/book/phabricator/article/arcanist/
Source0:    https://github.com/phacility/arcanist/archive/%{git_full_version_hash}.tar.gz#/arcanist-%{git_full_version_hash}.tar.gz
BuildArch:  noarch

Requires:   bash-completion
Requires:   php(language) >= 5
Requires:   php-cli
Requires:   arcanist(libphutil) <= %{ver_months_ahead}
Requires:   arcanist(libphutil) >= %{ver_months_behind}

%description
A command line interface to Phabricator

%prep
%setup -q -n arcanist-%{git_full_version_hash}

# Not used by anyone other than upstream developers?
rm -rf scripts/breakout.py

%build

%install
# copy arcanist to the buildroot
mkdir -p %{buildroot}%{_datadir}/%{name}
cp -a bin/ resources/ scripts/ src/ %{buildroot}%{_datadir}/%{name}/

mkdir -p %{buildroot}%{_datadir}/bash-completion/completions/
cp -a resources/shell/bash-completion %{buildroot}%{_datadir}/bash-completion/completions/arc

# symlink the bin
mkdir -p %{buildroot}%{_bindir}
pushd %{buildroot}%{_bindir}
ln -s %{_datadir}/%{name}/bin/arc
popd

find %{buildroot}%{_datadir}/%{name}/ -type d -name test -exec rm -rvf {} \; 2>/dev/null || :
find %{buildroot}%{_datadir}/%{name}/ -type d -name __tests__ -exec rm -rvf {} \; 2>/dev/null || :

# Fix shebangs
find %{buildroot}%{_datadir}/%{name}/ -type f -exec sed -i -r -e 's"^#!(.*)/usr/bin/env php"#!%{_bindir}/php"' {} \;
find %{buildroot}%{_datadir}/%{name}/ -type f -exec sed -i -r -e 's"^#!(.*)/usr/bin/env bash"#!%{_bindir}/bash"' {} \;

%files
%{!?_licensedir:%global license %doc}
%license LICENSE
%doc README.md
%doc NOTICE
%{_datadir}/bash-completion/completions/arc
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/bin
%{_datadir}/%{name}/resources
%{_datadir}/%{name}/scripts
%{_datadir}/%{name}/src
%{_bindir}/arc

%changelog
* Thu May 17 2018 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 1:0.20180514.git733ac805-1
- Promote Week #20 2018

* Thu Jun 15 2017 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 1:0.20170609.git0c53a35d-1
- Promote Week #23 2017

* Sun May 28 2017 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 1:0.20170520.git21fe0792-9
- Rebuild

* Tue Mar 14 2017 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20170225.git822bc53-1
- Promote Week #08 2017

* Thu Feb 23 2017 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20170218.gita232e95-1
- Promote Week #07 2017

* Thu Feb 09 2017 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20170107.git9503b94-3
- Rebuild

* Sun Jan 22 2017 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20170107.git9503b94-2
- Rebuild

* Wed Jan 18 2017 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20170107.git9503b94-1
- Promote Week #01 2017

* Tue Dec 13 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20161022.gite17fe43-8
- Rebuild

* Sat Dec 03 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20161022.gite17fe43-7
- Rebuild

* Sat Dec 03 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20161022.gite17fe43-6
- Rebuild

* Thu Dec 01 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20161022.gite17fe43-5
- Rebuild

* Thu Dec 01 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20161022.gite17fe43-4
- Rebuild

* Thu Dec 01 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20161022.gite17fe43-3
- Rebuild

* Thu Dec 01 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20161022.gite17fe43-2
- Rebuild

* Thu Dec 01 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0.20161022.gite17fe43-1
- Rebuild

* Tue Nov 29 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 20161022.gite17fe43-1
- Promote Week #42 2016

* Mon Oct 24 2016 Jeroen van Meeuwen (Ergo Project) <jeroen.van.meeuwen@ergo-project.org> - 20161022.gite17fe43-1
- Promote Week #42

* Thu Sep  8 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 20160827.git10e5194-1
- Promote week #34

* Wed Aug 10 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 20160806.gitc9337c2-1
- Correct NEVRA
- Take an initial stab at addressing rpmlint errors

* Tue Aug  9 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 20160727.gitc9337c2-1
- Change the versioning scheme back to the original

* Wed Aug  3 2016 Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> - 0-0.20160727.gitf1c45a3
- Change over the versioning scheme to use the release, not the version

* Wed Feb 11 2015 Tim Flink <tflink@fedoraproject.org> - 20151211.git3f132f4-1
- updating to latest git

* Thu Dec 04 2014 Tim Flink <tflink@fedoraproject.org> - 20141204.gitb46d4ed-1
- updating to latest git

* Tue Sep 02 2014 Tim Flink <tflink@fedoraproject.org> - 20140902.gitc8f1513-1
- updating to latest git

* Mon Jul 21 2014 Tim Flink <tflink@fedoraproject.org> - 20140721.gitef18ae0-1
- updating to latest git

* Sun May 18 2014 Tim Flink <tflink@fedoraproject.org> - 20140518.git0468be3-1
- updating to latest git

* Thu Jan 23 2014 Tim Flink <tflink@fedoraproject.org> - 20140123.git2c2c566-1
- updating to latest git

* Tue Dec 10 2013 Tim Flink <tflink@fedoraproject.org> - 20131210.gite0b4eef-1
- updating to latest git

* Wed Oct 30 2013 Tim Flink <tflink@fedoraproject.org> - 20131030.gitaabbdbd-1
- Initial package