forked from xuanxu/citation-file-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcitation_info.rb
47 lines (33 loc) · 1.85 KB
/
citation_info.rb
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
begin
citation_file_path = ENV["CITATION_FILE_PATH"].to_s
if !citation_file_path.empty? && File.exist?(citation_file_path)
citation_cff_contents = File.read(citation_file_path)
if citation_cff_contents.empty?
system("echo 'CITATION.cff file is empty: #{citation_file_path}'")
else
citation_info_msg = <<~CITATIONINFO
**Ensure proper citation** by uploading a plain text CITATION.cff file to the default branch of your repository.
If using GitHub, a *Cite this repository* menu will appear in the About section, containing both APA and BibTeX formats. When exported to Zotero using a browser plugin, Zotero will automatically create an entry using the information contained in the .cff file.
You can copy the contents for your CITATION.cff file here:
<details><summary><strong>CITATION.cff</strong></summary>
<p>
```
#{citation_cff_contents}
```
</p>
</details>
If the repository is not hosted on GitHub, a .cff file can still be uploaded to set your preferred citation. Users will be able to manually copy and paste the citation.
Find more information on .cff files [here](https://github.com/citation-file-format/citation-file-format/blob/main/README.md) and [here](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-citation-files).
CITATIONINFO
File.open('citation_info_msg.txt', 'w') do |f|
f.write citation_info_msg
end
system("gh issue comment #{ENV['ISSUE_ID']} --body-file citation_info_msg.txt")
end
else
system("echo 'No citation .cff file found #{citation_file_path}'")
end
rescue Exception => e
system("echo '!! Error creating the citation info. #{citation_file_path} : #{e.message}'")
system("echo '!! #{e.backtrace}'")
end